Example #1
0
        private IMethodElement FindExtensionMethodInClass(IClassElement classElement, string methodName, ITypeElement callerType, Expression qualifier)
        {
            if (classElement == null || callerType == null)
            {
                return(null);
            }

            bool isCaseSensitiveLanguage = CodeRush.Language.IsCaseSensitive;

            IMemberElementCollection classElementMembers = classElement.Members;

            foreach (IElement member in classElementMembers)
            {
                IMethodElement method = member as IMethodElement;
                if (method == null)
                {
                    continue;
                }

                if (String.Compare(method.Name, methodName, !isCaseSensitiveLanguage) == 0)
                {
                    if (method.IsExtensionMethod())
                    {
                        if (ExtendsTheCallerType(method, callerType, qualifier))
                        {
                            return(method);
                        }
                    }
                }
            }
            return(null);
        }
 public static Method GetSetupMethod(this IClassElement currentClass)
 {
     if (!currentClass.IsTestClass())
         return null;
     var attributeSection = (AttributeSection)(((Class)currentClass).Nodes.OfType<LanguageElement>().First(n => n.ElementType == LanguageElementType.AttributeSection && _setupMethodAttributes.Contains(n.FirstDetail.Name)));
     return attributeSection.TargetNode as Method;
 }
Example #3
0
 public static bool AlreadyImplementsIDisposable(IClassElement iClassElement)
 {
     ITypeElement[] baseTypes = iClassElement.GetBaseTypes();
       foreach (ITypeElement item in baseTypes)
     if (item.Is("System.IDisposable"))
       return true;
       return false;
 }
        public bool AddChartPoint(string varName, out IChartPoint chartPnt)
        {
            chartPnt = null;
            IClassElement codeClass = codeClassMethod.GetClass();

            CP.Code.IClassVarElement codeElem = codeClass.GetVar(varName);
            if (codeElem != null)
            {
                return(AddChartPoint(codeElem, out chartPnt, false));
            }

            return(false);
        }
 public void CalcInjectionPoints(CPClassLayout cpInjPoints, CP.Code.IModel model)
 {
     foreach (IChartPoint cp in chartPoints)
     {
         bool needDeclare = false;
         if (cp.data.enabled)
         {
             IClassElement codeClass = codeClassMethod.GetClass();
             CPTraceVar    traceVar  = cp.CalcInjectionPoints(cpInjPoints, codeClass.name, out needDeclare);
             codeClass.CalcInjectionPoints(cpInjPoints, traceVar, needDeclare);
             model.CalcInjectionPoints(cpInjPoints, traceVar);
         }
     }
 }
Example #6
0
        private IClassElement GetStaticClass(IElement element)
        {
            IClassElement classElement = element as IClassElement;

            if (classElement == null)
            {
                return(null);
            }
            if (!classElement.IsStatic)
            {
                return(null);
            }
            return(classElement);
        }
Example #7
0
 public static IList<IFieldElement> GetDisposableFieldsThatHaveNotBeenDisposed(ScopeResolveResult resolveResult, ISourceFile scope, IClassElement iClassElement, out IIfStatement parentIfDisposing)
 {
     parentIfDisposing = null;
       IList<IFieldElement> disposableFields = new List<IFieldElement>();
       foreach (IElement child in iClassElement.AllChildren)
       {
     if (child.FirstFile == null)
       continue;
     // fix for partial classes
     if (child.FirstFile.Name != scope.Name)
       continue;
     IFieldElement iBaseVariable = child as IFieldElement;
     if (iBaseVariable != null)
     {
       if (CanAnalyseAsDisposable(iBaseVariable) &&
     iBaseVariable.Is("System.IDisposable") && !IsDisposed(resolveResult, iClassElement, iBaseVariable))
     disposableFields.Add(iBaseVariable);
     }
     else
       if (parentIfDisposing == null)
       {
     IMethodElement iMethodElement = child as IMethodElement;
     if (iMethodElement != null && iMethodElement.Name == STR_Dispose && iMethodElement.Parameters.Count == 1)
     {
       string paramName = iMethodElement.Parameters[0].Name;
       foreach (IElement potentialStatement in iMethodElement.AllChildren)
       {
         IIfStatement iIfStatement = potentialStatement as IIfStatement;
         if (iIfStatement != null)
         {
           IExpression condition = iIfStatement.Condition;
           if (condition != null && (condition.Name == paramName || (condition is ILogicalOperationExpression && (condition as ILogicalOperationExpression).LeftSide.Name == paramName)))
           {
             // We have found the "if (disposing)" block of code!
             parentIfDisposing = iIfStatement;
             break;
           }
         }
       }
     }
       }
       }
       return disposableFields;
 }
 public static bool IsTestClass(this IClassElement currentClass)
 {
     return currentClass.Attributes.OfType<LanguageElement>().Count(a => _testClassAttributes.Contains(a.Name)) > 0;
 }
    private IMethodElement FindExtensionMethodInClass(IClassElement classElement, string methodName, ITypeElement callerType,Expression qualifier)
    {
      if (classElement == null || callerType == null)
        return null;

      bool isCaseSensitiveLanguage = CodeRush.Language.IsCaseSensitive;

      IMemberElementCollection classElementMembers = classElement.Members;
      foreach (IElement member in classElementMembers)
      {
        IMethodElement method = member as IMethodElement;
        if (method == null)
          continue;

        if (String.Compare(method.Name, methodName, !isCaseSensitiveLanguage) == 0)
          if (method.IsExtensionMethod())
            if (ExtendsTheCallerType(method, callerType, qualifier))
              return method;
      }
      return null;
    }
Example #10
0
 private static bool IsDisposed(ScopeResolveResult resolveResult, IClassElement scope, IFieldElement field)
 {
     if (scope == null || field == null)
     return false;
       IElementCollection references = field.FindAllReferences(scope);
       foreach (IElement reference in references)
       {
     IElement parent = reference.Parent;
     if (parent != null)
     {
       IWithSource withSource = parent as IWithSource;
       if (withSource != null)
       {
     if (withSource.Source == reference)
     {
       if (parent.Name == STR_Dispose)
       {
         IMethodElement parentMethod = reference.ParentMethod;
         if (parentMethod != null && parentMethod.Name == STR_Dispose)
           return true;
       }
     }
       }
       // B188310
       if (IsAddedToControls(parent))
     return true;
       if (ComponentsInstancePassedIntoConstructor(resolveResult, parent))
     return true;
       if (PassedIntoDifferentDisposeMethod(resolveResult, parent, reference))
     return true;
     }
       }
       return false;
 }
Example #11
0
 public void StoreClass(IClassElement classElem)
 {
     classes.Add(classElem);
 }