public BehaviorElement CreateBehavior(IDeclaredElement field)
        {
            IClass clazz = field.GetContainingType() as IClass;

            if (clazz == null)
            {
                return(null);
            }

            ContextElement context;

            _cache.Classes.TryGetValue(clazz, out context);
            if (context == null)
            {
                return(null);
            }

            string fullyQualifiedTypeName = null;

            if (field is ITypeOwner)
            {
                // Work around the difference in how the MetaData API and Psi API return different type strings for generics.
                TypeNameCache.TryGetValue(GetFirstGenericNormalizedTypeName(field), out fullyQualifiedTypeName);
            }

            return(new BehaviorElement(_provider,
                                       context,
                                       _projectEnvoy,
                                       clazz.CLRName,
                                       field.ShortName,
                                       field.IsIgnored(),
                                       fullyQualifiedTypeName));
        }
Esempio n. 2
0
        public ContextSpecificationElement CreateContextSpecification(IDeclaredElement field)
        {
#if RESHARPER_6
            IClass clazz = ((ITypeMember)field).GetContainingType() as IClass;
#else
            IClass clazz = field.GetContainingType() as IClass;
#endif
            if (clazz == null)
            {
                return(null);
            }

            ContextElement context;
            _cache.Classes.TryGetValue(clazz, out context);
            if (context == null)
            {
                return(null);
            }

            return(GetOrCreateContextSpecification(_provider,
#if RESHARPER_61
                                                   _manager, _psiModuleManager, _cacheManager,
#endif
                                                   _project,
                                                   context,
                                                   _projectEnvoy,
#if RESHARPER_6
                                                   clazz.GetClrName().FullName,
#else
                                                   clazz.CLRName,
#endif
                                                   field.ShortName,
                                                   clazz.GetTags(),
                                                   field.IsIgnored()));
        }
        public ContextSpecificationElement CreateContextSpecification(IDeclaredElement field)
        {
            IClass clazz = field.GetContainingType() as IClass;

            if (clazz == null)
            {
                return(null);
            }

            ContextElement context;

            _cache.Classes.TryGetValue(clazz, out context);
            if (context == null)
            {
                return(null);
            }

            return(new ContextSpecificationElement(_provider,
                                                   context,
                                                   _projectEnvoy,
                                                   clazz.CLRName,
                                                   field.ShortName,
                                                   clazz.GetTags(),
                                                   field.IsIgnored()));
        }
    public BehaviorElement CreateBehavior(IDeclaredElement field)
    {
      IClass clazz = field.GetContainingType() as IClass;
      if (clazz == null)
      {
        return null;
      }

      ContextElement context;
      _cache.Classes.TryGetValue(clazz, out context);
      if (context == null)
      {
        return null;
      }

      string fullyQualifiedTypeName = null;
      if (field is ITypeOwner)
      {
          // Work around the difference in how the MetaData API and Psi API return different type strings for generics.
          TypeNameCache.TryGetValue(GetFirstGenericNormalizedTypeName(field), out fullyQualifiedTypeName);
      }

      return new BehaviorElement(_provider,
                                 context,
                                 _projectEnvoy,
                                 clazz.CLRName,
                                 field.ShortName,
                                 field.IsIgnored(),
                                 fullyQualifiedTypeName);
    }
    public ContextSpecificationElement CreateContextSpecification(IDeclaredElement field)
    {
#if RESHARPER_6
      IClass clazz = ((ITypeMember)field).GetContainingType() as IClass;
#else
      IClass clazz = field.GetContainingType() as IClass;
#endif
      if (clazz == null)
      {
        return null;
      }

      ContextElement context;
      _cache.Classes.TryGetValue(clazz, out context);
      if (context == null)
      {
        return null;
      }

      return GetOrCreateContextSpecification(_provider,
                                             _project,
                                             context,
                                             _projectEnvoy,
#if RESHARPER_6
                                             clazz.GetClrName().FullName,
#else
                                             clazz.CLRName,
#endif
                                             field.ShortName,
                                             clazz.GetTags(),
                                             field.IsIgnored());
    }
 BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior,
                                                          IDeclaredElement behaviorSpecification)
 {
   return new BehaviorSpecificationElement(_provider,
                                           behavior,
                                           _projectEnvoy,
                                           behaviorSpecification.GetContainingType().CLRName,
                                           behaviorSpecification.ShortName,
                                           behaviorSpecification.IsIgnored());
 }
Esempio n. 7
0
 BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior,
                                                          IDeclaredElement behaviorSpecification)
 {
     return(new BehaviorSpecificationElement(_provider,
                                             behavior,
                                             _project,
                                             behaviorSpecification.GetContainingType().CLRName,
                                             behaviorSpecification.ShortName,
                                             behaviorSpecification.IsIgnored()));
 }
        // This will be called multiple times in the case of chained method calls.
        public override void VisitInvocationExpression(IInvocationExpression invocationExpressionParam)
        {
            // TODO: Loop through here somehow and work up through the string calls like ToLower().ToUpper() et et.
            //do
//          {
            IReferenceExpression expression = invocationExpressionParam.InvokedExpression as IReferenceExpression;

            if (expression == null)
            {
                return;
            }

            // As I understand it this takes the abstract syntax element that is e.ToString() and resolves it such that
            // we know it's the System.Enum.ToString() method call.
            IResolveResult resolveResult = expression.Reference.Resolve();

            IDeclaredElement e = resolveResult.DeclaredElement;

            if (e == null)
            {
                return;
            }

            ITypeElement containingType = e.GetContainingType();


            // work up through the string calls
            //invocationExpressionParam = invocationExpressionParam.InvocationExpressionReference as IInvocationExpression;
            //var allowed = new[] { "ToUpper", "ToLower", "ToString" };
            //if (!new List<string>(allowed).Contains(e.ShortName))
            //    return;
//          }
            //while (containingType != null && containingType.CLRName == "System.String");

            if (containingType == null)
            {
                return;
            }

            if (containingType.CLRName == "System.Enum" && e.ShortName == "ToString")
            {
                Found = true;

                // Save the enum declaration so we can implement the fix.
                this.FoundEnumReference = invocationExpressionParam.Reference;
                this.EnumReferenceName  = expression.QualifierExpression.GetText();

                IExpressionType qe = expression.QualifierExpression.GetExpressionType();
                this.EnumDeclaredName = ((IDeclaredType)qe).GetPresentableName(PsiLanguageType.GetByProjectFile(invocationExpressionParam.GetProjectFile()));
            }
        }
    BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior,
                                                             IDeclaredElement behaviorSpecification)
    {
      return new BehaviorSpecificationElement(_provider,
                                              behavior,
                                              _projectEnvoy,
#if RESHARPER_6
                                              behavior.FullyQualifiedTypeName ?? ((ITypeMember)behaviorSpecification).GetContainingType().GetClrName().FullName,
#else
                                              behavior.FullyQualifiedTypeName ?? behaviorSpecification.GetContainingType().CLRName,
#endif
 behaviorSpecification.ShortName,
                                              behaviorSpecification.IsIgnored());
    }
Esempio n. 10
0
        /// <summary>
        /// Gets the full name of the method.
        /// </summary>
        /// <param name="method">
        /// The method.
        /// </param>
        /// <returns>
        /// The get full method name.
        /// </returns>
        public static string GetFullMethodName(IDeclaredElement method)
        {
            var result = method.ShortName;

              var typeElement = method.GetContainingType();
              if (typeElement != null)
              {
            result = typeElement.ShortName + "." + result;

            var ns = typeElement.GetContainingNamespace();

            result = ns.QualifiedName + "." + result;
              }

              return result;
        }
Esempio n. 11
0
        /// <summary>
        /// Determines if the declared element is contained in a MSpec-related container type,
        /// i.e.: Context, context base class, class with <see cref="BehaviorsAttribute" />.
        /// </summary>
        static bool IsInSpecificationContainer(IDeclaredElement declaredElement)
        {
#if RESHARPER_6
            ITypeElement containingType = null;
            if (declaredElement is ITypeMember)
            {
                containingType = ((ITypeMember)declaredElement).GetContainingType();
            }
            else if (declaredElement is ITypeElement)
            {
                containingType = (ITypeElement)declaredElement;
            }
#else
            var containingType = declaredElement.GetContainingType();
#endif
            return(IsContext(containingType) || containingType.IsBehaviorContainer() || IsContextBase(containingType));
        }
        public BehaviorElement CreateBehavior(IDeclaredElement field)
        {
#if RESHARPER_6
            IClass clazz = ((ITypeMember)field).GetContainingType() as IClass;
#else
            IClass clazz = field.GetContainingType() as IClass;
#endif
            if (clazz == null)
            {
                return(null);
            }

            ContextElement context;
            _cache.Classes.TryGetValue(clazz, out context);
            if (context == null)
            {
                return(null);
            }

            string fullyQualifiedTypeName = null;
            if (field is ITypeOwner)
            {
                // Work around the difference in how the MetaData API and Psi API return different type strings for generics.
                TypeNameCache.TryGetValue(GetFirstGenericNormalizedTypeName(field), out fullyQualifiedTypeName);
            }

            return(GetOrCreateBehavior(_provider,
#if RESHARPER_61
                                       _manager, _psiModuleManager, _cacheManager,
#endif
                                       _project,
                                       _projectEnvoy,
                                       context,
#if RESHARPER_6
                                       clazz.GetClrName().FullName,
#else
                                       clazz.CLRName,
#endif
                                       field.ShortName,
                                       field.IsIgnored(),
                                       fullyQualifiedTypeName));
        }
    public BehaviorElement CreateBehavior(IDeclaredElement field)
    {
#if RESHARPER_6
      IClass clazz = ((ITypeMember)field).GetContainingType() as IClass;
#else
      IClass clazz = field.GetContainingType() as IClass;
#endif
      if (clazz == null)
      {
        return null;
      }

      ContextElement context;
      _cache.Classes.TryGetValue(clazz, out context);
      if (context == null)
      {
        return null;
      }

      string fullyQualifiedTypeName = null;
      if (field is ITypeOwner)
      {
          // Work around the difference in how the MetaData API and Psi API return different type strings for generics.
          TypeNameCache.TryGetValue(GetFirstGenericNormalizedTypeName(field), out fullyQualifiedTypeName);
      }

      return GetOrCreateBehavior(_provider,
#if RESHARPER_61
                                 _manager, _psiModuleManager, _cacheManager, 
#endif
                                 _project,
                                 _projectEnvoy,
                                 context,
#if RESHARPER_6
                                 clazz.GetClrName().FullName,
#else
                                 clazz.CLRName,
#endif
                                 field.ShortName,
                                 field.IsIgnored(),
                                 fullyQualifiedTypeName);
    }
    public ContextSpecificationElement CreateContextSpecification(IDeclaredElement field)
    {
      IClass clazz = field.GetContainingType() as IClass;
      if (clazz == null)
      {
        return null;
      }

      ContextElement context = _cache.Classes[clazz];
      if (context == null)
      {
        return null;
      }

      return new ContextSpecificationElement(_provider,
                                             context,
                                             _project,
                                             clazz.CLRName,
                                             field.ShortName,
                                             field.IsIgnored());
    }
Esempio n. 15
0
        public BehaviorElement CreateBehavior(IDeclaredElement field)
        {
            IClass clazz = field.GetContainingType() as IClass;
              if (clazz == null)
              {
            return null;
              }

              ContextElement context = ContextCache.Classes[clazz];
              if (context == null)
              {
            return null;
              }

              return new BehaviorElement(_provider,
                                 context,
                                 _project,
                                 clazz.CLRName,
                                 field.ShortName,
                                 field.IsIgnored());
        }
    public ContextSpecificationElement CreateContextSpecification(IDeclaredElement field)
    {
      IClass clazz = field.GetContainingType() as IClass;
      if (clazz == null)
      {
        return null;
      }

      ContextElement context;
      _cache.Classes.TryGetValue(clazz, out context);
      if (context == null)
      {
        return null;
      }

      return new ContextSpecificationElement(_provider,
                                             context,
                                             _projectEnvoy,
                                             clazz.CLRName,
                                             field.ShortName,
                                             clazz.GetTags(),
                                             field.IsIgnored());
    }
        public BehaviorElement CreateBehavior(IDeclaredElement field)
        {
            IClass clazz = field.GetContainingType() as IClass;

            if (clazz == null)
            {
                return(null);
            }

            ContextElement context;

            _cache.Classes.TryGetValue(clazz, out context);
            if (context == null)
            {
                return(null);
            }

            return(new BehaviorElement(_provider,
                                       context,
                                       _project,
                                       clazz.CLRName,
                                       field.ShortName,
                                       field.IsIgnored()));
        }
 /// <summary>
 /// Determines if the declared element is contained in a MSpec-related container type,
 /// i.e.: Context, context base class, class with <see cref="BehaviorsAttribute" />.
 /// </summary>
 static bool IsInSpecificationContainer(IDeclaredElement declaredElement)
 {
   var containingType = declaredElement.GetContainingType();
   return IsContext(containingType) || containingType.IsBehaviorContainer() || IsContextBase(containingType);
 }
        BehaviorSpecificationElement CreateBehaviorSpecification(BehaviorElement behavior,
                                                                 IDeclaredElement behaviorSpecification)
        {
            return(GetOrCreateBehaviorSpecification(_provider,
#if RESHARPER_61
                                                    _manager, _psiModuleManager, _cacheManager,
#endif
                                                    _project,
                                                    behavior,
                                                    _projectEnvoy,
#if RESHARPER_6
                                                    behavior.FullyQualifiedTypeName ?? ((ITypeMember)behaviorSpecification).GetContainingType().GetClrName().FullName,
#else
                                                    behavior.FullyQualifiedTypeName ?? behaviorSpecification.GetContainingType().CLRName,
#endif
                                                    behaviorSpecification.ShortName,
                                                    behaviorSpecification.IsIgnored()));
        }
    /// <summary>
    /// Determines if the declared element is contained in a MSpec-related container type,
    /// i.e.: Context, context base class, class with <see cref="BehaviorsAttribute" />.
    /// </summary>
    static bool IsInSpecificationContainer(IDeclaredElement declaredElement)
    {
#if RESHARPER_6
      ITypeElement containingType = null;
      if (declaredElement is ITypeMember)
        containingType = ((ITypeMember) declaredElement).GetContainingType();
      else if (declaredElement is ITypeElement)
        containingType = (ITypeElement) declaredElement;
#else
      var containingType = declaredElement.GetContainingType();
#endif
      return IsContext(containingType) || containingType.IsBehaviorContainer() || IsContextBase(containingType);
    }
 static bool IsBehavior(IDeclaredElement declaredElement)
 {
   return declaredElement.IsBehavior() && IsTestElement(declaredElement.GetContainingType());
 }
 static bool IsInTestElementOrContext(IDeclaredElement declaredElement)
 {
     return IsTestElement(declaredElement.GetContainingType()) || IsContextBase(declaredElement.GetContainingType());
 }
 static bool IsSupportingField(IDeclaredElement declaredElement)
 {
   return declaredElement.IsSupportingField() &&
          (IsTestElement(declaredElement.GetContainingType()) || IsContextBase(declaredElement.GetContainingType()));
 }
        /// <summary>
        /// Determines if the declared element is contained in a MSpec-related container type,
        /// i.e.: Context, context base class, class with <see cref="BehaviorsAttribute" />.
        /// </summary>
        static bool IsInSpecificationContainer(IDeclaredElement declaredElement)
        {
            var containingType = declaredElement.GetContainingType();

            return(IsContext(containingType) || containingType.IsBehaviorContainer() || IsContextBase(containingType));
        }