예제 #1
0
        public void Navigate()
        {
            if (_elementActivated == null || _targetClass == null)
            {
                return;
            }

            Method activatedMethod = _elementActivated.GetDeclaration() as Method;

            if (activatedMethod == null)
            {
                return;
            }

            Method matchingMethodInClass = FindMatchingMethodInClass(activatedMethod);

            if (matchingMethodInClass == null)
            {
                return;
            }

            CodeRush.File.Activate(matchingMethodInClass.FileNode.FilePath);

            CodeRush.Documents.ActiveTextView.Selection.Set(matchingMethodInClass.NameRange);
        }
예제 #2
0
        public void Load(LanguageElement element)
        {
            Reset();

            if (!OnCall(element))
            {
                return;
            }

            IElement declaration = element.GetDeclaration();

            if (declaration == null)
            {
                return;
            }

            Class declaringType = declaration.Parent as Class;

            if (declaringType == null)
            {
                return;
            }

            if (declaringType is Interface || (declaringType.IsAbstract))
            {
                LoadImplementors(declaringType);
            }
        }
예제 #3
0
        private bool IsMethodCall(LanguageElement Item)
        {
            if (Item is MethodCall)
            {
                // Calls which discard any returned value.
                return true;
            }
            if (Item is MethodCallExpression)
            {
                // Method calls which are themselves passed to other methods.
                return true;
            }
            // C# requires parenthesis for it's method calls. This makes identifying method calls very easy.
            // Other languages (VB.Net for example) do not share this requirement.
            // References to Methods and Variables end up looking exactly the same to the parser.
            // ElementReferenceExpressions may potentially refer to Methods.
            if (!(Item is ElementReferenceExpression))
                return false;

            // This forces us to locate the declaration of the item the reference points at.
            // Once there we can confirm if the Item in question is a Method.
            if (!(Item.GetDeclaration() is IMethodElement))
                return false;

            // Finally we need to confirm that the method reference is in fact a call.
            // We do this by eliminating the other purpose of a method reference: That of a Method pointer.
            // No parent AddressOf operator. Therefore not a method pointer.
            if (!(Item.Parent is AddressOfExpression))
                return true;
            return false;
        }
        protected override bool IsValidSelection(LanguageElement element, TextViewSelection selection)
        {
            if ((element == null) || (selection == null))
                return false;
            if (selection.Exists)
                return false;
            var creationExpression = element.Parent as ObjectCreationExpression;

            return creationExpression != null && element.GetDeclaration() == null;
        }
        protected override bool IsValidSelection(LanguageElement element, TextViewSelection selection)
        {
            if ((element == null) || (selection == null))
            {
                return(false);
            }
            if (selection.Exists)
            {
                return(false);
            }
            var creationExpression = element.Parent as ObjectCreationExpression;

            return(creationExpression != null && element.GetDeclaration() == null);
        }
    private static IElement GetElementDeclaration(LanguageElement element)
    {
      IElement declaration;

      if (elementIsReference(element.ElementType))
        declaration = element.GetDeclaration();
      else
        declaration = element;

      if (declaration != null && elementTypeIsSupported(declaration.ElementType))
        return declaration;

      return null;
    }
        private static IElement GetElementDeclaration(LanguageElement element)
        {
            IElement declaration;

            if (elementIsReference(element.ElementType))
            {
                declaration = element.GetDeclaration();
            }
            else
            {
                declaration = element;
            }

            if (declaration != null && elementTypeIsSupported(declaration.ElementType))
            {
                return(declaration);
            }

            return(null);
        }
예제 #8
0
        private static IWithParameters GetValidDeclaration(LanguageElement originalCall)
        {
            if (originalCall == null)
            {
                return(null);
            }

            IElement declaration = originalCall.GetDeclaration(false);

            if (declaration is IMethodElement)
            {
                return(declaration as IWithParameters);
            }
            IEventElement eventElement = declaration as IEventElement;

            if (eventElement != null && eventElement.Type != null)
            {
                return(eventElement.Type.Resolve(ParserServices.SourceTreeResolver) as IWithParameters);
            }
            return(null);
        }
예제 #9
0
        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);
        }
예제 #10
0
    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;
    }
 /// <summary>
 /// Is class
 /// </summary>
 private static bool IsClass(LanguageElement element)
 {
     IElement declaration = element.GetDeclaration();
     return (declaration as IClassElement) != null;
 } // IsClass
예제 #12
0
 private TypeDeclaration GetTypeDeclarationForElement(LanguageElement element)
 {
     return(element.GetDeclaration() as TypeDeclaration);
 }
    private static IWithParameters GetValidDeclaration(LanguageElement originalCall)
    {
      if (originalCall == null)
        return null;

      IElement declaration = originalCall.GetDeclaration(false);
      if (declaration is IMethodElement)
        return declaration as IWithParameters;
      IEventElement eventElement = declaration as IEventElement;
      if (eventElement != null && eventElement.Type != null)
      {
        return eventElement.Type.Resolve(ParserServices.SourceTreeResolver) as IWithParameters;
      }
      return null;
    }
 private TypeDeclaration GetTypeDeclarationForElement(LanguageElement element)
 {
     return element.GetDeclaration() as TypeDeclaration;
 }
예제 #15
0
        /// <summary>
        /// Is class
        /// </summary>
        private static bool IsClass(LanguageElement element)
        {
            IElement declaration = element.GetDeclaration();

            return((declaration as IClassElement) != null);
        } // IsClass
 private bool CheckReference(LanguageElement element)
 {
     return(ShouldColorize(element.GetDeclaration() as LanguageElement));
 }