Ejemplo n.º 1
0
		/// <summary>
		/// Processes a node, before its descendants are processed.
		/// </summary>
		/// <param name="element">The node to process.</param>
		public override void ProcessBeforeInterior(ITreeNode element) {
			string attributeId = GetHighlightingAttributeId(element);
			if (attributeId != null) {
				DocumentRange range = element.GetHighlightingRange();
				AddHighlighting(new HighlightingInfo(range, new PredefinedHighlighting(attributeId, range)));
			}
		}
        public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var statements = match.GetMatchedElementList("statements").Cast<ICSharpStatement>();

                var collectedTypes = statements.SelectMany(statement =>
                {
                    var returnTypeCollector = new ReturnTypeCollector(new UniversalContext(statement.GetPsiModule()));
                    statement.ProcessThisAndDescendants(returnTypeCollector);
                    return returnTypeCollector.CollectedTypes;
                });

                foreach (var type in collectedTypes)
                {
                    var declaredType = type as IDeclaredType;
                    if (declaredType != null)
                    {
                        var typeElement = declaredType.GetTypeElement();
                        if (typeElement != null)
                        {
                            yield return new ServiceRegistration(registrationRootElement, typeElement);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var argument = match.GetMatchedElement(ElementName) as ICSharpArgument;
                if (argument == null)
                {
                    yield break;
                }

                // match typeof() expressions
                var typeOfExpression = argument.Value as ITypeofExpression;
                if (typeOfExpression != null)
                {
                    var typeElement = ((IDeclaredType)typeOfExpression.ArgumentType).GetTypeElement();
                    if (typeElement == null) // can happen if the typeof() expression is empty
                    {
                        yield break;
                    }

                    yield return new ComponentRegistration(registrationRootElement, typeElement);
                }
            }
        }
        /// <summary>
        /// The code must not contain multiple whitespace in a row.
        /// </summary>
        /// <param name="node">
        /// The node.
        /// </param>
        public void CodeMustNotContainMultipleWhitespaceInARow(ITreeNode node)
        {
            for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling)
            {
                if (currentNode is ITokenNode)
                {
                    ITokenNode currentToken = currentNode as ITokenNode;
                    ITokenNode previousToken = currentToken.GetPrevToken();

                    if (previousToken != null)
                    {
                        if (currentToken.GetTokenType() == CSharpTokenType.WHITE_SPACE && previousToken.GetTokenType() == CSharpTokenType.WHITE_SPACE)
                        {
                            using (WriteLockCookie.Create(true))
                            {
                                LowLevelModificationUtil.DeleteChild(currentToken);
                            }
                        }
                    }
                }

                if (currentNode.FirstChild != null)
                {
                    this.CodeMustNotContainMultipleWhitespaceInARow(currentNode.FirstChild);
                }
            }
        }
Ejemplo n.º 5
0
 public TreeConnection(ITreeNode ignParent, ITreeNode ignChild, List<DPoint> lstPt)
     : this()
 {
     IgnChild = ignChild;
     IgnParent = ignParent;
     LstPt = lstPt;
 }
Ejemplo n.º 6
0
        public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            // This entire thing is one big hack. Need to come back to it one day :)
            // There is (currently) no way to create a pattern that would match the Bind() call with implicit this in ReSharper SSR.
            // Therefore I'm only matching by the method name only, and later verifying that the method invocation's qualifier
            // is indeed derived from global::Ninject.Syntax.IBindingRoot

            if (!IsNinjectBindCall(registrationRootElement))
            {
                yield break;
            }

            IExpressionStatement statement = GetParentExpressionStatemenmt(registrationRootElement);
            if (statement == null)
            {
                yield break;
            }
            foreach (var toPattern in toPatterns)
            {
                var implementedByRegistration = toPattern.GetComponentRegistrations(statement.Expression)
                    .Cast<ComponentRegistration>()
                    .FirstOrDefault();

                if (implementedByRegistration != null)
                {
                    foreach (var registration in DoCreateRegistrations(statement.Expression).OfType<ComponentRegistration>())
                    {
                        registration.Implementation = implementedByRegistration.ServiceType;
                        yield return registration;
                    }
                }
            }
        }
Ejemplo n.º 7
0
 private static bool IsAssignment(ITreeNode referenceExpression)
 {
     var binaryexpression = referenceExpression.Parent as IBinaryExpression;
     return binaryexpression != null &&
            binaryexpression.LeftOperand == referenceExpression &&
            IsAssignmentImpl(binaryexpression);
 }
        private static void PrintTree(IDomainTree domainTree, ITreeNode node, String tab = "")
        {
            var outputAttributeId = domainTree.Attributes.Count - 1;

            if (node.IsLeaf())
            {
                var values = domainTree.GetAllSymbolicValuesOfAttribute(SymbolicDomainDataParams.CreateIt(node.Data, outputAttributeId));
                if (values.Length == 0)
                {
                    Console.WriteLine("{0}\t{1} = \"null\";", tab, domainTree.Attributes[outputAttributeId]);
                }
                else
                {
                    Console.WriteLine("{0}\t{1} = \"{2}\";", tab, domainTree.Attributes[outputAttributeId],
                                  domainTree.Domain[outputAttributeId][values[0]]);
                }

                return;
            }

            var numvalues = node.Children.Length;
            for (var i = 0; i < numvalues; i++)
            {
                Console.WriteLine(tab + "if( " + domainTree.Attributes[node.TestAttribute] + " == \"" +
                                  domainTree.Domain[node.TestAttribute][i] + "\") {");
                PrintTree(domainTree, node.Children[i], tab + "\t");

                if (i != numvalues - 1)
                    Console.Write(tab + "} else ");
                else
                    Console.WriteLine(tab + "}");
            }
        }
 private static void GetNodePairs(ITreeNode firstNode, ITreeNode lastNode, IList<FormattingRange> list)
 {
     var firstChild = firstNode;
     var lastChild = lastNode;
     var commonParent = firstNode.FindCommonParent(lastNode);
     while (firstChild != null && firstChild.Parent != commonParent)
     {
         firstChild = firstChild.Parent;
     }
     while (lastChild != null && lastChild.Parent != commonParent)
     {
         lastChild = lastChild.Parent;
     }
     Assertion.Assert(firstChild != null, "firstChild != null");
     Assertion.Assert(lastChild != null, "lastChild != null");
     var node = firstChild;
     while (node != null && node != lastChild.NextSibling)
     {
         if (!node.IsWhitespaceToken())
         {
             GetNodePairs(node, list, commonParent);
         }
         node = node.NextSibling;
     }
 }
 // Same
 public bool HasReference(ITreeNode element, ICollection<string> names)
 {
     var literal = element as ILiteralExpression;
     if (literal != null && literal.ConstantValue.Value is string)
         return names.Contains((string)literal.ConstantValue.Value);
     return false;
 }
Ejemplo n.º 11
0
        public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            var parentExpression = registrationRootElement.GetParentExpression<IExpressionStatement>();
            if (parentExpression == null)
            {
                yield break;
            }

            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var expression = match.GetMatchedElement<ICSharpExpression>("expression");

                if (IsResolvedToObject(expression))
                {
                    yield break;
                }

                IEnumerable<IComponentRegistration> componentRegistrations = GetRegistrationsFromExpression(registrationRootElement, expression);

                IEnumerable<FilteredRegistrationBase> basedOnRegistrations = basedOnPatterns.SelectMany(
                   basedOnPattern => basedOnPattern.GetBasedOnRegistrations(parentExpression.Expression)).ToList();

                var registrations = componentRegistrations.Concat(basedOnRegistrations).ToList();

                if (registrations.Any())
                {
                    yield return new CompositeRegistration(registrationRootElement, registrations);
                }
            }
        }
        public void ProcessBeforeInterior(ITreeNode element)
        {
            var declaration = element as IDeclaration;
            if (declaration == null)
                return;

            var declaredElement = declaration.DeclaredElement;
            if (declaredElement == null || declaredElement.ShortName == SharedImplUtil.MISSING_DECLARATION_NAME)
                return;

            IUnitTestElement testElement = null;
            var testClass = declaredElement as IClass;
            if (testClass != null)
                testElement = ProcessTestClass(testClass);

            var testMethod = declaredElement as IMethod;
            if (testMethod != null)
                testElement = ProcessTestMethod(testMethod);

            if (testElement != null)
            {
                var nameRange = declaration.GetNameDocumentRange().TextRange;
                var documentRange = declaration.GetDocumentRange().TextRange;
                if (nameRange.IsValid && documentRange.IsValid)
                {
                    var disposition = new UnitTestElementDisposition(testElement, psiFile.GetSourceFile().ToProjectFile(),
                                                                     nameRange, documentRange);
                    consumer(disposition);
                }
            }
        }
        public bool InteriorShouldBeProcessed(ITreeNode element)
        {
            if (element is ITypeMemberDeclaration)
                return (element is ITypeDeclaration);

            return true;
        }
        /// <summary>
        /// The get component registrations.
        /// </summary>
        /// <param name="registrationRootElement">
        /// The registration root element.
        /// </param>
        /// <returns>
        /// </returns>
        public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var invocationExpression = match.MatchedElement as IInvocationExpression;
                if (invocationExpression == null)
                {
                    yield break;
                }

                if (invocationExpression.TypeArguments.Count > 0)
                {
                    foreach (IComponentRegistration registration in FromGenericArguments(invocationExpression))
                    {
                        yield return registration;
                    }
                }
                else
                {
                    foreach (IComponentRegistration registration in FromArguments(invocationExpression))
                    {
                        yield return registration;
                    }
                }
            }
        }
        public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            IExpressionStatement parentExpression = GetParentExpressionStatemenmt(registrationRootElement);
            if (parentExpression == null)
            {
                yield break;
            }

            IStructuralMatchResult match = Match(registrationRootElement);
            if (match.Matched)
            {
                var arguments = match.GetMatchedElementList("assemblies").Cast<ICSharpArgument>();

                IEnumerable<IModule> modules = arguments.SelectNotNull(argument => ModuleExtractor.GetTargetModule(argument.Value));

                foreach (IModule module in modules)
                {
                    var registration = new ModuleBasedOnRegistration(module, new DefaultScanAssemblyRegistration(registrationRootElement));

                    var basedOnRegistrations = BasedOnPatterns.SelectMany(
                        basedOnPattern => basedOnPattern.GetBasedOnRegistrations(parentExpression.Expression));

                    yield return new CompositeRegistration(registrationRootElement, registration, basedOnRegistrations.ToArray());
                }
            }
        }
Ejemplo n.º 16
0
        public override IEnumerable<BasedOnRegistrationBase> GetBasedOnRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var argument = match.GetMatchedElement("argument") as ICSharpArgument;
                if (argument == null)
                {
                    yield break;
                }

                var typeofExpression = argument.Value as ITypeofExpression;
                if (typeofExpression != null)
                {
                    var declaredType = typeofExpression.ArgumentType as IDeclaredType;
                    if (declaredType != null)
                    {
                        ITypeElement typeElement = declaredType.GetTypeElement();
                        if (typeElement != null)
                        {
                            yield return registrationCreator.Create(registrationRootElement, typeElement);
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public override IEnumerable<IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            // ReSharper does not currently match generic and non-generic overloads separately, meaning that Register<T> and Register(typeof(T))
            // will be both matched with a single pattern Register($arguments$).
            // Therefire I am using this pattern to look for both generic and non-generic (with typeof) overloads of the pattern

            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var invocationExpression = match.MatchedElement as IInvocationExpression;
                if (invocationExpression == null)
                {
                    yield break;
                }

                if (invocationExpression.TypeArguments.Any())
                {
                    foreach (var registration in FromGenericArguments(invocationExpression))
                    {
                        yield return registration;
                    }
                }
                else
                {
                    foreach (var registration in FromArguments(invocationExpression))
                    {
                        yield return registration;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public BasedOnRegistration(ITreeNode registrationRootElement, ITypeElement basedOnElement)
            : base(registrationRootElement)
        {
            this.basedOnElement = basedOnElement;

            name = basedOnElement.GetClrName().FullName;
        }
    public PsiUnresolvedVariableReferenceHighlighting(IVariableName element)
    {
      myElement = element;

      myReference = (element as VariableName).Reference;

    }
        public IReference[] GetReferences(ITreeNode element, IReference[] oldReferences)
        {
            var literal = element as ILiteralExpression;
            if (literal != null && literal.ConstantValue.Value is string)
            {
                var agument = literal.Parent as IVBArgument;
                var attribute = AttributeNavigator.GetByArgument(agument);
                if (attribute != null)
                {
                    var @class = attribute.AttributeType.Reference.Resolve().DeclaredElement as IClass;
                    if (@class != null && Equals(@class.GetClrName(), DataAttributeName))
                    {
                        var typeElement = (from a in attribute.Arguments
                                           where a is INamedArgument && a.ArgumentName == TypeMemberName
                                           select GetTypeof(a.Expression as IGetTypeExpression)).FirstOrDefault();

                        var member = MethodDeclarationNavigator.GetByAttribute(attribute) as ITypeMemberDeclaration;
                        if (member != null && member.DeclaredElement != null && typeElement == null)
                            typeElement = member.DeclaredElement.GetContainingType();

                        if (typeElement == null)
                            return EmptyArray<IReference>.Instance;

                        var reference = CreateReference(typeElement, literal);

                        return oldReferences != null && oldReferences.Length == 1 && Equals(oldReferences[0], reference)
                                   ? oldReferences
                                   : new[] { reference };
                    }
                }
            }

            return EmptyArray<IReference>.Instance;
        }
Ejemplo n.º 21
0
        private static bool IsAssignmentImpl(ITreeNode binaryexpression)
        {
            var treeElement = binaryexpression.FirstChild;
            if (treeElement == null)
                return false;

            for (; treeElement != null; treeElement = treeElement.NextSibling)
            {
                var javaScriptTokenBase = treeElement as JavaScriptTokenBase;
                if (javaScriptTokenBase != null)
                {
                    NodeType nodeType = javaScriptTokenBase.NodeType;
                    if (nodeType == JavaScriptTokenType.EQ ||
                        nodeType == JavaScriptTokenType.PLUSEQ ||
                        nodeType == JavaScriptTokenType.MINUSEQ ||
                        nodeType == JavaScriptTokenType.TIMESEQ ||
                        nodeType == JavaScriptTokenType.PERCENTEQ ||
                        nodeType == JavaScriptTokenType.LSHIFTEQ ||
                        nodeType == JavaScriptTokenType.RSHIFTEQ ||
                        nodeType == JavaScriptTokenType.GT3EQ ||
                        nodeType == JavaScriptTokenType.AMPEREQ ||
                        nodeType == JavaScriptTokenType.PIPEEQ ||
                        nodeType == JavaScriptTokenType.CAROTEQ ||
                        nodeType == JavaScriptTokenType.DIVIDEEQ)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
        public IReference[] GetReferences(ITreeNode element, IReference[] oldReferences)
        {
            var literal = element as ILiteralExpression;
            if (literal != null && literal.ConstantValue.Value is string)
            {
                var attribute = AttributeNavigator.GetByConstructorArgumentExpression(literal as ICSharpExpression);
                if (attribute != null)
                {
                    var @class = attribute.Name.Reference.Resolve().DeclaredElement as IClass;
                    if (@class != null && Equals(@class.GetClrName(), DataAttributeName))
                    {
                        var typeElement = (from a in attribute.PropertyAssignments
                                           where a.PropertyNameIdentifier.Name == TypeMemberName
                                           select GetTypeof(a.Source as ITypeofExpression)).FirstOrDefault();

                        var member = MethodDeclarationNavigator.GetByAttribute(attribute);
                        if (member != null && member.DeclaredElement != null && typeElement == null)
                            typeElement = member.DeclaredElement.GetContainingType();

                        if (typeElement == null)
                            return EmptyArray<IReference>.Instance;

                        var reference = CreateReference(typeElement, literal);

                        return oldReferences != null && oldReferences.Length == 1 && Equals(oldReferences[0], reference)
                                   ? oldReferences
                                   : new[] {reference};
                    }
                }
            }

            return EmptyArray<IReference>.Instance;
        }
        /// <summary>
        /// Replace one node with another.
        /// </summary>
        /// <param name="rootNode">The root node.</param>
        /// <param name="replaceThisNode">The node to replace.</param>
        /// <param name="replaceWith">What to replace with.</param>
        public static void Process(ITreeNode rootNode, ITreeNode replaceThisNode, ITreeNode replaceWith)
        {
            bool done = false;

            DepthFirstTraversal trav = new DepthFirstTraversal();
            trav.Traverse(rootNode, (n) =>
            {
                if (done)
                {
                    return false;
                }

                for (int i = 0; i < n.ChildNodes.Count; i++)
                {
                    ITreeNode childNode = n.ChildNodes[i];
                    if (childNode == replaceThisNode)
                    {
                        n.ChildNodes[i] = replaceWith;
                        done = true;
                        return false;
                    }
                }
                return true;
            });
        }
Ejemplo n.º 24
0
        private void Compile(ITreeNode node, StringBuilder builder)
        {
            if (node.Descriptor != "ROOT")
            {
                builder.Append(node.Descriptor);
                builder.Append('{');
            }
            foreach(var child in node.Children)
            {
                Compile(child, builder);
            }

            foreach(var expression in node.Expressions)
            {
                builder.Append(expression.Expression.Key);
                builder.Append(':');
                builder.Append(expression.Expression.Value);
                builder.Append(';');
            }

            if (node.Descriptor != "ROOT")
            {
                builder.Append('}');
            }
        }
Ejemplo n.º 25
0
        IEnumerable<BasedOnRegistrationBase> IBasedOnPattern.GetBasedOnRegistrations(ITreeNode registrationRootElement)
        {
            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                ITreeNode element = match.GetMatchedElement("argument");
                if (element != null)
                {
                    foreach (var whereArgumentPattern in whereArgumentPatterns)
                    {
                        var registrations = whereArgumentPattern.GetBasedOnRegistrations(element).ToArray();
                        if (!registrations.Any())
                        {
                            // try with the root element.
                            registrations = whereArgumentPattern.GetBasedOnRegistrations(registrationRootElement).ToArray();
                        }

                        foreach (var registration in registrations)
                        {
                            yield return registration;
                        }
                    }
                }
            }
        }
Ejemplo n.º 26
0
        public void Drop(ITreeNode targetData)
        {
            if (targetData ==null )
            {

            }
        }
        protected override bool HasReference(ITreeNode element, ICollection<string> names)
        {
            var stringLiteral = element as IJavaScriptLiteralExpression;
            if (stringLiteral == null)
                return false;

            var file = element.GetContainingFile();
            if (file == null)
                return false;

            // TODO: We can't use this, due to losing data when we reparse for code completion
            // When we start code completion, the tree node is reparsed with new text inserted,
            // so that references have something to attach to. Reparsing works with IChameleon
            // blocks that allow for resync-ing in-place. Our AngularJs nodes don't have any
            // chameleon blocks (for JS, it's the Block class - anything with braces) so we end
            // up re-parsing the file. This creates a new IFile, (in a sandbox that allows access
            // to the original file's reference provider) but it doesn't copy the user data. We
            // could theoretically look for a containing sandbox, get the context node and try
            // and get the user data there, but that just makes it feel like this is the wrong
            // solution. I think maybe this should be a reference provider for HTML, not AngularJs.
            // It would have the context of the attribute name, but should really work with the
            // injected AngularJs language, if only to see that it's a string literal
            //var originalAttributeType = file.UserData.GetData(AngularJsFileData.OriginalAttributeType);
            //if (originalAttributeType != elementTypes.AngularJsUrlType.Name)
            //    return false;

            return true;
        }
 public PsiIntentionResult(List<ITemplateFieldHolder> holders, IDeclaration declaration, ITreeNode anchor, DocumentRange range)
 {
   myDeclaration = declaration;
   myHolders = holders;
   myPrefferedSelection = range;
   myAnchor = anchor;
 }
Ejemplo n.º 29
0
 protected void _newChild(ITreeNode nTreeNode)
 {
     if (null != m_tNewChildTreeNode)
     {
         this.m_tNewChildTreeNode(nTreeNode);
     }
 }
Ejemplo n.º 30
0
 public TokenHighlighting(ITreeNode element)
 {
     myElement = element;
     string lang = element.UserData.GetData(Constants.YcLanguage);
     string tokenName = element.UserData.GetData(Constants.YcTokenName);
     attributeId = LanguageHelper.GetColor(lang, tokenName);
 }