private bool ExtendsTheCallerType(IMethodElement method, ITypeElement callerType, Expression qualifier)
        {
            if (method == null || callerType == null)
                return false;

            if (method.Parameters.Count == 0)
                return false;
            ISourceTreeResolver resolver = ParserServices.SourceTreeResolver;
            ExpressionCollection arguments = new ExpressionCollection();
            arguments.Add(qualifier);
            method = GenericElementActivator.ActivateMemberIfNeeded(resolver, method, arguments, null, ArgumentsHelper.ResolveArgumentTypes(resolver, arguments)) as IMethodElement;

            if (method == null)
                return false;

            IParameterElement extensionParam = method.Parameters[0] as IParameterElement;
            if (extensionParam == null)
                return false;

            ITypeReferenceExpression typeRef = extensionParam.Type;
            if (typeRef == null)
                return false;
            ITypeElement type = typeRef.GetDeclaration() as ITypeElement;
            if (type == null)
                return false;
            IArrayTypeElement arrayType = callerType as IArrayTypeElement;
            //if (arrayType != null)
            //{
            //  return true;
            //}
            //else
            return ArgumentsHelper.HasParamConversion(resolver, extensionParam, callerType, qualifier, TypeConversionMode.ImplicitConversion);
        }
    private bool IsValidReferenceAndQualifier(LanguageElement activeRerence, out ITypeElement callerType, out Expression qualifier)
    {
      qualifier = null;
      callerType = null;
      if (!(activeRerence is IHasQualifier))
        return false;

      // should be undeclared....
      IElement declaration = activeRerence.GetDeclaration(false);
      if (declaration != null)
        return false;


      qualifier = (activeRerence as IHasQualifier).Qualifier;
      if (qualifier is MethodReferenceExpression)
        qualifier = (qualifier as MethodReferenceExpression).Qualifier;
      if (qualifier == null)
        return false;

      callerType = qualifier.Resolve(ParserServices.SourceTreeResolver) as ITypeElement;
      if (callerType == null)
        return false;

      return true;
    }
        public BasedOnRegistration(ITreeNode registrationRootElement, ITypeElement basedOnElement, IEnumerable<WithServiceRegistration> withServices)
            : base(registrationRootElement, withServices)
        {
            this.basedOnElement = basedOnElement;

            name = basedOnElement.GetClrName().FullName;
        }
Beispiel #4
0
 private void SetConstructorsState(ITypeElement typeElement, UsageState state)
 {
     foreach (IConstructor constructor in typeElement.Constructors)
     {
         collectUsagesStageProcess.SetElementState(constructor, state);
     }
 }
    public ContextElement CreateContext(ITypeElement type)
    {
      if (_cache.Classes.ContainsKey(type))
      {
        return _cache.Classes[type];
      }

      var context = GetOrCreateContextElement(_provider,
#if RESHARPER_61
                                              _manager,
                                              _psiModuleManager,
                                              _cacheManager,
#endif
                                              _project,
                                              _projectEnvoy,
                                              type.GetClrName().FullName,
                                              _assemblyPath,
                                              type.GetSubjectString(),
                                              type.GetTags(),
                                              type.IsIgnored());

      foreach (var child in context.Children)
      {
        child.State = UnitTestElementState.Pending;
      }

      _cache.Classes.Add(type, context);
      return context;
    }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            if (!types.Contains(typeElement))
                return false;

            return basedOn.IsSatisfiedBy(typeElement);
        }
 public SearchGenericImplementationsRequest(DeclaredElementTypeUsageInfo declaredElement,
                                            ITypeElement originType,
                                            ISearchDomain searchDomain,
                                            IEnumerable<IDeclaredType> originTypeParams)
     : base(declaredElement, originType, searchDomain) {
     _originTypeParams = originTypeParams;
 }
 public ControlFlowInspector([NotNull] ICSharpFunctionDeclaration functionDeclaration,
     [NotNull] CSharpControlFlowGraf graf, int maxLevel, [NotNull] ITypeElement disposableInterface)
     : base(functionDeclaration, graf)
 {
     _disposableInterface = disposableInterface;
     _maxLevel = maxLevel;
 }
        public BasedOnRegistration(ITreeNode registrationRootElement, ITypeElement basedOnElement)
            : base(registrationRootElement)
        {
            this.basedOnElement = basedOnElement;

            name = basedOnElement.GetClrName().FullName;
        }
 /// <summary>
 /// Is element of type
 /// </summary>
 public bool IsElementOfType(ITypeElement DeclaredTypeElement, string type)
 {
     if (DeclaredTypeElement == null)
         return false;
     if (DeclaredTypeElement.FullName.Replace("`1", "") == type || DeclaredTypeElement.DescendsFrom(type))
         return true;
     return false;
 } // IsElementOfType(DeclaredTypeElement, type)
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            if (!typeElement.IsDescendantOf(basedOnElement))
            {
                return false;
            }

            return base.IsSatisfiedBy(typeElement);;
        }
public override bool IsSatisfiedBy(ITypeElement typeElement)
{
    if (!defaultFilter(typeElement))
            {
                return false;
            }

            return withServices.All(registration => registration.IsSatisfiedBy(typeElement));
}
        public ComponentRegistration(ITreeNode registrationElement, ITypeElement serviceType)
            : base(registrationElement)
        {
            this.serviceType = serviceType;

            // for some reason, in tests this throws an exception
            // copying the name to display later in ToString()
            name = GetDisplayName(serviceType);
        }
public override bool IsSatisfiedBy(ITypeElement typeElement)
{
    if (defaultFilter(typeElement))
            {
                return true;
            }

            return false;
}
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            var attributesOwner = typeElement as IAttributesOwner;
            if (attributesOwner == null)
            {
                return false;
            }

            return attributesOwner.HasAttributeInstance(attributeType.GetClrName(), true);
        }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            IModule targetModule = typeElement.Module.ContainingProjectModule;
            if (targetModule == null)
            {
                return false;
            }

            return (targetModule.Equals(sourceModule) && basedOn.IsSatisfiedBy(typeElement));
        }
 public void AddContext(ITypeElement type, ContextElement context)
 {
     if (!this._contexts.ContainsKey(type))
     {
         this._contexts.Add(type, context);
     }
     else
     {
         this._contexts[type] = context;
     }
 }
Beispiel #18
0
        public static bool TryGetTypeElement(string typeName, IPsiModule psiModule, IModuleReferenceResolveContext moduleReferenceResolveContext, out ITypeElement typeElement)
        {
            typeElement = null;

            var typeByClrName = CreateTypeByCLRName(typeName, psiModule, moduleReferenceResolveContext);
            if (typeByClrName != null)
            {
                typeElement = typeByClrName.GetTypeElement();
            }

            return typeElement != null;
        }
        private static string GetDisplayName(ITypeElement element)
        {
            IClrTypeName clrName = element.GetClrName();

            string fullName = string.Format("{0}.{1}", clrName.GetNamespaceName(), clrName.ShortName);

            if (element.HasTypeParameters())
            {
                fullName = string.Format("{0}<>", fullName);
            }

            return fullName;
        }
 public ControlFlowInspector([NotNull] ICSharpFunctionDeclaration functionDeclaration,
     [NotNull] CSharpControlFlowGraf graf, [NotNull] ITypeElement disposableInterface)
     : base(functionDeclaration, graf)
 {
     _disposableInterface = disposableInterface;
     _disposableArguments = GetDisposableArguments();
     if (_disposableArguments != null)
     {
         _processThis = IsThisDisposable();
         _elementDataStorage = InitElementDataStorage();
         _psiSourceFile = functionDeclaration.GetSourceFile();
     }
 }
Beispiel #21
0
            public ClosingTypesRegistration(ITreeNode registrationRootElement, ITypeElement openGenericType)
                : base(registrationRootElement)
            {
                AddFilter(typeElement =>
                {
                    var @interface = openGenericType as IInterface;
                    if ([email protected]())
                    {
                        return false;
                    }

                    return typeElement.ClosesOver(openGenericType);
                });
            }
            public TypesRegistration(ITreeNode registrationRootElement, ITypeElement basedOnElement)
                : base(registrationRootElement, basedOnElement)
            {
                AddFilter(typeElement =>
                {
                    var @class = typeElement as IClass;
                    if (@class == null || @class.IsAbstract || @class.IsStaticClass())
                    {
                        return false;
                    }

                    return true;
                });
            }
        public static Pair<ITypeElement, ITypeMember>? PropertyFromColorElement(ITypeElement qualifierType, IColorElement colorElement, IPsiModule module)
        {
            var colorName = UnityNamedColors.GetColorName(colorElement.RGBColor);
            if (string.IsNullOrEmpty(colorName))
                return null;

            var unityColorType = GetInstance(module).UnityColorType;
            if (unityColorType == null || !unityColorType.Equals(qualifierType)) return null;

            var colorProperties = GetStaticColorProperties(unityColorType);
            var propertyTypeMember = colorProperties.FirstOrDefault(p => p.ShortName == colorName);
            if (propertyTypeMember == null) return null;

            return Pair.Of(unityColorType, propertyTypeMember);
        }
            public TypesRegistration(ITreeNode registrationRootElement, ITypeElement basedOnElement)
                : base(registrationRootElement)
            {
                AddFilter(typeElement =>
                {
                    var @class = typeElement as IClass;
                    if (@class != null && @class.IsAbstract)
                    {
                        return false;
                    }

                    return true;
                });
                AddFilter(typeElement => typeElement.IsDescendantOf(basedOnElement));
            }
    public ContextElement CreateContext(ITypeElement type)
    {
      if (_cache.Classes.ContainsKey(type))
      {
        return _cache.Classes[type];
      }

      ContextElement context = new ContextElement(_provider,
                                                  _project,
                                                  type.CLRName,
                                                  _assemblyPath,
                                                  type.GetTags(),
                                                  type.IsIgnored());
      _cache.Classes.Add(type, context);
      return context;
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="ValueAnalysisRefactoring"/> class.
        /// </summary>
        /// <param name="typeMemberDeclaration">
        /// The type member declaration.
        /// </param>
        public ValueAnalysisRefactoring([NotNull] ITypeMemberDeclaration typeMemberDeclaration)
        {
            this.typeMemberDeclaration = typeMemberDeclaration;

              var codeAnnotationsCache = CodeAnnotationsCache.GetInstance(this.Solution);

              this.notNullTypeElement = codeAnnotationsCache.GetAttributeTypeForElement(this.TypeMemberDeclaration, CodeAnnotationsCache.NotNullAttributeShortName);
              this.canBeNullTypeElement = codeAnnotationsCache.GetAttributeTypeForElement(this.TypeMemberDeclaration, CodeAnnotationsCache.CanBeNullAttributeShortName);

              if (this.notNullTypeElement == null || this.canBeNullTypeElement == null)
              {
            return;
              }

              this.notNullableAttributeClrName = new CLRTypeName(this.notNullTypeElement.CLRName);
              this.canBeNullAttributeClrName = new CLRTypeName(this.canBeNullTypeElement.CLRName);
        }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            var elementNamespace = typeElement.GetContainingNamespace();

            bool isMatch;
            if (includeSubnamespaces)
            {
                isMatch = elementNamespace.QualifiedName == matchedNamespace.QualifiedName ||
                          elementNamespace.QualifiedName.StartsWith(matchedNamespace.QualifiedName + ".", StringComparison.OrdinalIgnoreCase);
            }
            else
            {
                isMatch = elementNamespace.QualifiedName == matchedNamespace.QualifiedName;
            }

            return isMatch && base.IsSatisfiedBy(typeElement);
        }
    public TypeInterfaceDescriptor(ITypeElement typeElement, bool instanceOnly) : base(typeElement.GetSolution())
    {
      AutoExpandSingleChild = true;
      myInstanceOnly = instanceOnly;

      // We use standard presenter, but emphasize root element using adorements
      myPresenter = new TypeInterfacePresenter
                      {
                        DrawElementExtensions = true,
                        ShowOccurenceCount = false,
                        PostfixTypeQualification = true
                      };
      myPresenter.PresentAdorements += PresentAdorements;

      // Wrap typeElement with an envoy, so it can survive code changes
      myTypeElementEnvoy = new DeclaredElementEnvoy<ITypeElement>(typeElement);
      MakeModel();
    }
        private static bool IsInsideInitializerToTypeWithSource(CheckContentAvailabilityEventArgs ea)
        {
            _TypeElement = null;
            _ObjectCreationExpression = ea.Element as ObjectCreationExpression;
            if (_ObjectCreationExpression == null)
            {
                _ObjectCreationExpression = ea.Element.GetParent(LanguageElementType.ObjectCreationExpression) as ObjectCreationExpression;
                if (_ObjectCreationExpression == null)
                    return false;
            }
            _InitializerExpression = _ObjectCreationExpression.ObjectInitializer;
            if (_InitializerExpression == null)
                return false;
            _TypeElement = _ObjectCreationExpression.ObjectType.Resolve(ParserServices.SourceTreeResolver) as ITypeElement;
            if (_TypeElement == null)
                return false;

            return !_TypeElement.InReferencedAssembly;
        }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            // todo for now assume that interfaces are not supported
            if (typeElement is IInterface)
            {
                return false;
            }

            if (Implementation != null)
            {
                if (Implementation.IsGenericInterface())
                {
                    return typeElement.IsDescendantOf(Implementation);
                }

                return Implementation.Equals(typeElement);
            }

            return serviceType.Equals(typeElement);
        }
Beispiel #31
0
 //Remove existing, but don't create a new one.
 protected override IAttribute CreateAttribute(ITypeElement resolvedAttributeType, CSharpElementFactory factory, IPsiModule psiModule) => null;
Beispiel #32
0
 public bool IsDescendantOfMonoBehaviour([CanBeNull] ITypeElement type)
 {
     return(IsDescendantOf(KnownTypes.MonoBehaviour, type));
 }
Beispiel #33
0
 private static bool IsDescendantOfUnityObject([CanBeNull] ITypeElement type)
 {
     return(IsDescendantOf(KnownTypes.Object, type));
 }
Beispiel #34
0
 protected FSharpGeneratedPropertyBase(ITypeElement typeElement) =>
Beispiel #35
0
 protected FSharpGeneratedPropertyFromTypeBase(ITypeElement containingType) =>
Beispiel #36
0
 public ReflectionMemberNotFoundError(IExpression nameArgument, DeclaredElementType elementType, ITypeElement type, BindingFlags?bindingFlags)
 {
     BindingFlags  = bindingFlags;
     _nameArgument = nameArgument;
     _elementType  = elementType;
     _type         = type;
 }
Beispiel #37
0
 public GetHashCodeMethod([NotNull] ITypeElement containingType) : base(containingType)
 {
 }
 public bool IsUnityType([NotNull] ITypeElement type)
 {
     return(GetBaseUnityTypes(type).Any());
 }
 public IEnumerable <UnityType> GetBaseUnityTypes([NotNull] ITypeElement type)
 {
     return(myTypes.Value.Where(c => type.IsDescendantOf(c.GetType(type.Module))));
 }
 private static bool HasTransformTextMethod([NotNull] ITypeElement typeElement)
 => typeElement
 .GetAllClassMembers(T4CSharpIntermediateConverterBase.TransformTextMethodName)
 .SelectNotNull(instance => instance.Member as IMethod)
 .Any(IsTransformTextMethod);
Beispiel #41
0
 private static void ChangeAnnotationAttribute(IMethodDeclaration methodDeclaration, string toReplace, ITypeElement replacement)
 {
     var toReplaceAttribute = methodDeclaration.Attributes
         .FirstOrDefault(a => string.Compare(a.Name.QualifiedName, toReplace, StringComparison.InvariantCultureIgnoreCase) == 0);
     if (toReplaceAttribute != null && replacement != null)
     {
         var annotation = CSharpAnnotationsUtil.Annotate(methodDeclaration, replacement);
         if (annotation.Status == CSharpAnnotationsUtil.Status.AnnotationInserted)
         {
             methodDeclaration.RemoveAttribute(toReplaceAttribute);
         }
     }
 }
Beispiel #42
0
 public bool ReferenceModuleWithType(IPsiModule module, ITypeElement typeToReference)
 {
     return(ReferenceModuleImpl(module, typeToReference.Module, typeToReference.GetContainingNamespace().QualifiedName));
 }
 public bool ReferenceModuleWithType(IPsiModule module, ITypeElement typeToReference, IModuleReferenceResolveContext resolveContext)
 {
     return(ReferenceModuleWithType(module, typeToReference));
 }
Beispiel #44
0
 protected GeneratedMethodWithOneParam([NotNull] ITypeElement containingType) : base(containingType)
 {
 }
Beispiel #45
0
 public ToStringMethod([NotNull] ITypeElement containingType) : base(containingType)
 {
 }
Beispiel #46
0
 public EqualsSimpleTypeMethod([NotNull] ITypeElement containingType) : base(containingType)
 {
 }
 public bool IsUnityColorType([CanBeNull] ITypeElement typeElement)
 {
     return((UnityColorType != null && UnityColorType.Equals(typeElement)) ||
            (UnityColor32Type != null && UnityColor32Type.Equals(typeElement)));
 }
Beispiel #48
0
 public bool IsDescendantOfScriptableObject([CanBeNull] ITypeElement type)
 {
     return(IsDescendantOf(KnownTypes.ScriptableObject, type));
 }
 public bool IsUnityColorTypeSupportingHSV([CanBeNull] ITypeElement typeElement)
 {
     return(UnityColorType != null && UnityColorType.Equals(typeElement));
 }
 public PreferGenericMethodOverloadQuickFix(PreferGenericMethodOverloadWarning warning)
 {
     myInvocationExpression = warning.InvocationMethod;
     myMethodName           = warning.MethodName;
     myTargetType           = warning.TypeElement;
 }
Beispiel #51
0
 private static bool EqualSubstitutions([NotNull] ITypeElement referenceOwner, [NotNull] ISubstitution referenceSubstitution, [NotNull] ITypeElement originOwner, [NotNull] ISubstitution originSubstitution)
 {
     foreach (var substitution1 in referenceOwner.GetAncestorSubstitution(originOwner))
     {
         var substitution2 = substitution1.Apply(referenceSubstitution);
         foreach (var typeParameter in substitution2.Domain)
         {
             if (originSubstitution.HasInDomain(typeParameter) && !substitution2[typeParameter].IsEquals(originSubstitution[typeParameter]))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #52
0
 public EqualsObjectWithComparerMethod([NotNull] ITypeElement containingType) : base(containingType)
 {
 }
Beispiel #53
0
 public IEnumerable <UnityType> GetBaseUnityTypes([NotNull] ITypeElement type)
 {
     return(myTypes.Value.Where(t => t.SupportsVersion(myUnityVersion.Version) && type.IsDescendantOf(t.GetType(type.Module))));
 }
Beispiel #54
0
 public CompareToSimpleTypeMethod([NotNull] ITypeElement containingType) : base(containingType)
 {
 }
Beispiel #55
0
 public static bool IsDescendantOfUnityEvent([CanBeNull] ITypeElement type)
 {
     return(IsDescendantOf(KnownTypes.UnityEvent, type));
 }
Beispiel #56
0
 public CompareToObjectMethod([NotNull] ITypeElement containingMember) : base(containingMember)
 {
 }
        private static void CheckMethodGroup(
            [NotNull] IReferenceExpression methodReference,
            [NotNull] IMethod method, [NotNull] IHighlightingConsumer consumer)
        {
            string message    = null;
            var    methodType = method.GetContainingType();

            if (methodType is IInterface)
            {
                message = string.Format("from interface '{0}' method", methodType.ShortName);
                consumer.AddHighlighting(
                    new SlowDelegateCreationHighlighting(methodReference, message),
                    methodReference.GetExpressionRange());
                return;
            }

            // there is not lags if method is instance method
            if (!method.IsStatic &&
                methodReference.QualifierExpression != null &&
                methodReference.QualifierExpression.IsClassifiedAsVariable)
            {
                return;
            }

            var substitution   = methodReference.Reference.Resolve().Result.Substitution;
            var typeParameters = new JetHashSet <ITypeParameter>();

            // collect all the type parameters from the method reference
            if (!substitution.IsEmpty())
            {
                foreach (var typeParameter in substitution.Domain)
                {
                    var substitutionType = substitution.Apply(typeParameter);
                    var targs            = TypeParametersCollectingVisitor.Collect(substitutionType);
                    typeParameters.UnionWith(targs);
                }
            }

            // get the delegate creation owner type, if member is not static
            var delegateCreationMember = methodReference.GetContainingTypeMemberDeclaration();

            if (delegateCreationMember == null || delegateCreationMember.DeclaredElement == null)
            {
                return;
            }

            ITypeElement delegateCreationOwnerType = null;

            if (!delegateCreationMember.DeclaredElement.IsStatic)
            {
                delegateCreationOwnerType = delegateCreationMember.DeclaredElement.GetContainingType();
            }

            // look for implicit qualification with the type parameters
            ITypeElement lastType = null;

            for (var qualifier = methodReference; qualifier != null;
                 qualifier = qualifier.QualifierExpression as IReferenceExpression)
            {
                if (qualifier.IsClassifiedAsVariable)
                {
                    lastType = null;
                    break;
                }

                var resolveResult = qualifier.Reference.Resolve();
                lastType = resolveResult.DeclaredElement as ITypeElement;
            }

            if (lastType != null)
            {
                for (var hidden = lastType.GetContainingType(); hidden != null; hidden = hidden.GetContainingType())
                {
                    if (hidden.TypeParameters.Count > 0)
                    {
                        foreach (var typeParameter in hidden.TypeParameters)
                        {
                            typeParameters.Add(typeParameter);
                        }
                    }
                }
            }

            foreach (var parameter in typeParameters)
            {
                if (parameter.IsValueType)
                {
                    continue;
                }

                if (delegateCreationOwnerType != null &&
                    delegateCreationOwnerType.TypeParameters.Contains(parameter))
                {
                    continue;
                }

                if (message == null)
                {
                    message = "method group parametrized with type parameter ";
                }

                if (parameter.OwnerType != null)
                {
                    message += string.Format("'{0}' of type '{1}'", parameter.ShortName, parameter.OwnerType.ShortName);
                }
                else if (parameter.OwnerMethod != null)
                {
                    message += string.Format("'{0}' of method '{1}'", parameter.ShortName, parameter.OwnerMethod.ShortName);
                }
            }

            if (message != null)
            {
                consumer.AddHighlighting(
                    new SlowDelegateCreationHighlighting(methodReference, message),
                    methodReference.GetExpressionRange());
            }
        }
Beispiel #58
0
 public UnionTagProperty([NotNull] ITypeElement typeElement) : base(typeElement)
 {
 }
Beispiel #59
0
 public IEnumerable <ITypeElement> GetImplementedTypes(ITypeElement type)
 {
     return(type.DescendantsAndSelf(x => x.GetSuperTypes().Select(y => y.GetTypeElement())).Distinct());
 }
        public IEnumerable <AssetScriptUsages> GetAssetUsagesFor(IPsiSourceFile sourceFile, ITypeElement declaredElement)
        {
            myShellLocks.AssertReadAccessAllowed();

            var element = myPointers[sourceFile].GetElement(sourceFile, Id) as AssetUsagesDataElement;

            if (element == null)
            {
                return(Enumerable.Empty <AssetScriptUsages>());
            }

            var guid = AssetUtils.GetGuidFor(myMetaFileGuidCache, declaredElement);

            if (guid == null)
            {
                return(Enumerable.Empty <AssetScriptUsages>());
            }

            // TODO : should we cache result per guid in AssetUsagesDataElement?
            return(element.EnumerateAssetUsages().Where(t => t.UsageTarget.ExternalAssetGuid == guid));
        }