Example #1
0
        private void VisitViewdata(SpecialNodeInspector inspector)
        {
            AttributeNode attr     = inspector.TakeAttribute("default");
            Snippets      snippets = null;

            if (attr != null)
            {
                snippets = this.AsTextOrientedCode(attr);
            }
            AttributeNode node2 = inspector.TakeAttribute("model");

            if (node2 != null)
            {
                TypeInspector      inspector2 = new TypeInspector(this.AsCode(node2));
                ViewDataModelChunk chunk      = new ViewDataModelChunk {
                    TModel      = inspector2.Type,
                    TModelAlias = inspector2.Name
                };
                this.AddUnordered(chunk);
            }
            foreach (AttributeNode node3 in inspector.Attributes)
            {
                TypeInspector inspector3 = new TypeInspector(this.AsCode(node3));
                ViewDataChunk chunk2     = new ViewDataChunk {
                    Type     = inspector3.Type,
                    Name     = inspector3.Name ?? node3.Name,
                    Key      = node3.Name,
                    Default  = snippets,
                    Position = this.Locate(node3)
                };
                this.AddUnordered(chunk2);
            }
        }
Example #2
0
        private void VisitDefault(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            Frame frame = null;

            if (!specialNode.Element.IsEmptyElement)
            {
                ScopeChunk item = new ScopeChunk {
                    Position = this.Locate(specialNode.Element)
                };
                this.Chunks.Add(item);
                frame = new Frame(this, item.Body);
            }
            AttributeNode attr     = inspector.TakeAttribute("type");
            Snippets      snippets = (attr != null) ? this.AsCode(attr) : "var";

            foreach (AttributeNode node2 in inspector.Attributes)
            {
                DefaultVariableChunk chunk3 = new DefaultVariableChunk {
                    Type     = snippets,
                    Name     = node2.Name,
                    Value    = this.AsTextOrientedCode(node2),
                    Position = this.Locate(node2)
                };
                this.Chunks.Add(chunk3);
            }
            base.Accept(specialNode.Body);
            if (frame != null)
            {
                frame.Dispose();
            }
        }
Example #3
0
        public static Literal GetNamedAttributeValue(AttributeNode attr, Identifier name)
        {
            if (attr == null)
            {
                return(null);
            }
            ExpressionList exprs = attr.Expressions;

            if (exprs == null)
            {
                return(null);
            }
            for (int i = 0, n = exprs.Count; i < n; i++)
            {
                NamedArgument na = exprs[i] as NamedArgument;
                if (na == null)
                {
                    continue;
                }
                if (na.Name.UniqueIdKey == name.UniqueIdKey)
                {
                    return(na.Value as Literal);
                }
            }
            return(null);
        }
        private ProblemCollection CheckForProblems(AttributeNode attribute)
        {
            if (SemanticRulesUtilities.HasAttribute <ServiceContractAttribute>(attribute))
            {
                // reset the hasUnmatchedMessageHandler flag for each new type
                hasUnmatchedMessageHandler = false;
                return(base.Problems);
            }

            string action = SemanticRulesUtilities.GetAttributeValue <String>(attribute, "Action");

            if (SemanticRulesUtilities.HasAttribute <OperationContractAttribute>(attribute) &&
                !string.IsNullOrEmpty(action) &&
                action.Equals("*", StringComparison.OrdinalIgnoreCase))
            {
                // check if we already inspected another operation with unmatched message handler
                if (hasUnmatchedMessageHandler)
                {
                    Resolution resolution = base.GetResolution();
                    Problem    problem    = new Problem(resolution, attribute.SourceContext);
                    base.Problems.Add(problem);
                    return(base.Problems);
                }
                hasUnmatchedMessageHandler = true;
            }
            return(base.Problems);
        }
Example #5
0
        private FieldSymbol BuildPropertyAsField(PropertyDeclarationNode propertyNode, TypeSymbol typeSymbol)
        {
            AttributeNode intrinsicPropertyAttribute = AttributeNode.FindAttribute(propertyNode.Attributes, "IntrinsicProperty");

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

            TypeSymbol fieldType = typeSymbol.SymbolSet.ResolveType(propertyNode.Type, _symbolTable, typeSymbol);

            Debug.Assert(fieldType != null);

            if (fieldType != null)
            {
                FieldSymbol symbol = new FieldSymbol(propertyNode.Name, typeSymbol, fieldType);
                BuildMemberDetails(symbol, typeSymbol, propertyNode, propertyNode.Attributes);

                string scriptAlias = GetAttributeValue(propertyNode.Attributes, "ScriptAlias");
                if (scriptAlias != null)
                {
                    symbol.SetAlias(scriptAlias);
                }

                return(symbol);
            }

            return(null);
        }
Example #6
0
        private void VisitElse(SpecialNodeInspector inspector)
        {
            if (!this.SatisfyElsePrecondition())
            {
                throw new CompilerException("An 'else' may only follow an 'if' or 'elseif'.");
            }
            AttributeNode attr = inspector.TakeAttribute("if");

            if (attr == null)
            {
                ConditionalChunk chunk = new ConditionalChunk {
                    Type     = ConditionalType.Else,
                    Position = this.Locate(inspector.OriginalNode)
                };
                this.Chunks.Add(chunk);
                using (new Frame(this, chunk.Body))
                {
                    base.Accept(inspector.Body);
                    return;
                }
            }
            ConditionalChunk item = new ConditionalChunk {
                Type      = ConditionalType.ElseIf,
                Condition = this.AsCode(attr),
                Position  = this.Locate(inspector.OriginalNode)
            };

            this.Chunks.Add(item);
            using (new Frame(this, item.Body))
            {
                base.Accept(inspector.Body);
            }
        }
Example #7
0
        public override ASTNode VisitProperty([NotNull] CoolParser.PropertyContext context)
        {
            var node = new AttributeNode(context)
            {
                Formal = Visit(context.formal()) as FormalNode
            };

            if (context.expression() != null)
            {
                node.AssignExp = Visit(context.expression()) as ExpressionNode;
            }
            else if (node.Formal.Type.Text == "Int")
            {
                node.AssignExp = new IntNode(context, "0");
            }
            else if (node.Formal.Type.Text == "Bool")
            {
                node.AssignExp = new BoolNode(context, "false");
            }
            else if (node.Formal.Type.Text == "String")
            {
                node.AssignExp = new StringNode(context, "");
            }
            else
            {
                node.AssignExp = new VoidNode(node.Formal.Type.Text);
            }

            return(node);
        }
        private void ThenTheWrappedElementShouldHaveABlankAttributeNamed(string attribute)
        {
            Context.Target.CurrentNode.Attributes.ShouldContain(x => x.Name == attribute);
            AttributeNode attributeNode = Context.Target.CurrentNode.Attributes.Where(x => x.Name == attribute).First();

            attributeNode.Value.ShouldBeEmpty();
        }
Example #9
0
 public virtual AstNode VisitAttribute(AttributeNode n)
 {
     Visit(n.Target);
     Visit(n.Type);
     Visit(n.Arguments);
     return(n);
 }
        /// <summary>
        /// Checks the specified type.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public override ProblemCollection Check(TypeNode type)
        {
            AttributeNode attribute = SemanticRulesUtilities.GetAttribute(type, ServiceContractAttribute);

            if (SemanticRulesUtilities.HasAttribute <ServiceContractAttribute>(attribute))
            {
                List <string> duplicated = new List <string>();
                foreach (Member member in type.Members)
                {
                    if (SemanticRulesUtilities.GetAttribute(member, OperationContractAttribute) != null)
                    {
                        if (duplicated.Contains(member.Name.Name))
                        {
                            Resolution resolution = base.GetResolution(member.FullName);
                            Problem    problem    = new Problem(resolution, type.SourceContext);
                            base.Problems.Add(problem);
                        }
                        else
                        {
                            duplicated.Add(member.Name.Name);
                        }
                    }
                }
            }
            return(base.Problems);
        }
            public async override void Invoke()
            {
                ITextBuffer     textBuffer = this.HtmlSmartTag.TextBuffer;
                ElementNode     element    = this.HtmlSmartTag.Element;
                AttributeNode   src        = element.GetAttribute("src", true);
                ImageCompressor compressor = new ImageCompressor();

                bool isDataUri = src.Value.StartsWith("data:image/", StringComparison.Ordinal);

                if (isDataUri)
                {
                    string dataUri = await compressor.CompressDataUriAsync(src.Value);

                    if (dataUri.Length < src.Value.Length)
                    {
                        using (WebEssentialsPackage.UndoContext("Optimize image"))
                        {
                            Span span = Span.FromBounds(src.ValueRangeUnquoted.Start, src.ValueRangeUnquoted.End);
                            textBuffer.Replace(span, dataUri);
                        }
                    }
                }
                else
                {
                    var fileName = ImageQuickInfo.GetFullUrl(src.Value, textBuffer);

                    if (string.IsNullOrEmpty(fileName) || !ImageCompressor.IsFileSupported(fileName) || !File.Exists(fileName))
                    {
                        return;
                    }

                    await compressor.CompressFilesAsync(fileName);
                }
            }
        private bool HandleElement()
        {
            HtmlEditorDocument document = HtmlEditorDocument.TryFromTextView(_view);

            if (document == null)
            {
                return(false);
            }

            var tree = document.HtmlEditorTree;

            int position = _view.Caret.Position.BufferPosition.Position;

            ElementNode   tag  = null;
            AttributeNode attr = null;

            tree.GetPositionElement(position, out tag, out attr);

            if (tag != null && (tag.EndTag != null || tag.IsSelfClosing()))
            {
                int start = tag.Start;
                int end   = tag.End;

                Update(start, end);
                return(true);
            }

            return(false);
        }
Example #13
0
        private bool TryGetClassName(out string className)
        {
            int position = TextView.Caret.Position.BufferPosition.Position;

            className = null;

            ElementNode   element = null;
            AttributeNode attr    = null;

            _tree.GetPositionElement(position, out element, out attr);

            if (attr == null || attr.Name != "class")
            {
                return(false);
            }

            int beginning = position - attr.ValueRangeUnquoted.Start;
            int start     = attr.Value.LastIndexOf(' ', beginning) + 1;
            int length    = attr.Value.IndexOf(' ', start) - start;

            if (length < 0)
            {
                length = attr.ValueRangeUnquoted.Length - start;
            }

            className = attr.Value.Substring(start, length);

            return(true);
        }
        private bool TryGetPath(out string path)
        {
            int position = TextView.Caret.Position.BufferPosition.Position;

            path = null;

            ElementNode   element = null;
            AttributeNode attr    = null;

            _tree.GetPositionElement(position, out element, out attr);

            if (element == null)
            {
                return(false);
            }

            attr = element.GetAttribute("src") ?? element.GetAttribute("href");

            if (attr != null)
            {
                path = attr.Value;
                return(true);
            }

            return(false);
        }
        private static bool GetCenteredElement(AttributeNode elementClasses)
        {
            string[] columnSizeCenteredClasses = new string[] { "small-centered", "medium-centered", "large-centered",
                                                                "small-uncentered", "medium-uncentered", "large-uncentered" };

            return(columnSizeCenteredClasses.Any(x => elementClasses.Value.Split(' ').Any(y => y.Equals(x, StringComparison.OrdinalIgnoreCase))));
        }
Example #16
0
        public override IList <IHtmlValidationError> ValidateElement(ElementNode element)
        {
            var results = new ValidationErrorCollection();

            if (element.Name != "meta" || !element.HasAttribute("property"))
            {
                return(results);
            }

            AttributeNode property = element.GetAttribute("property");

            if (property.Value.StartsWith("og:", StringComparison.Ordinal))
            {
                ElementNode head = element.Parent;

                if (head != null && head.Name == "head")
                {
                    AttributeNode prefix = head.GetAttribute("prefix");
                    int           index  = element.Attributes.IndexOf(property);

                    if (prefix == null)
                    {
                        results.AddAttributeError(element, "The 'prefix' attribute on <head> for Open Graph is missing", HtmlValidationErrorLocation.AttributeValue, index);
                    }
                    else if (prefix.Value.IndexOf("og:", StringComparison.Ordinal) == -1)
                    {
                        results.AddAttributeError(element, "To use Open Graph, you must add the value 'og: http://ogp.me/ns#' to 'prefix' in <head>", HtmlValidationErrorLocation.AttributeValue, index);
                    }
                }
            }

            return(results);
        }
            private static void ReplaceUrlValue(string fileName, ITextBuffer buffer, AttributeNode src)
            {
                string relative = FileHelpers.RelativePath(buffer.GetFileName(), fileName);
                Span   span     = new Span(src.ValueRangeUnquoted.Start, src.ValueRangeUnquoted.Length);

                buffer.Replace(span, relative.ToLowerInvariant());
            }
Example #18
0
        protected override void Visit(ElementNode node)
        {
            AttributeNode node2 = node.Attributes.FirstOrDefault <AttributeNode>(attr => this.IsSpecialAttribute(node, attr));

            if (node2 != null)
            {
                SpecialNode item = this.CreateWrappingNode(node2, node);
                node.Attributes.Remove(node2);
                item.Body.Add(node);
                this.Nodes.Add(item);
                if (!node.IsEmptyElement)
                {
                    Frame frameData = new Frame {
                        ClosingName            = node.Name,
                        ClosingNameOutstanding = 1
                    };
                    base.PushFrame(item.Body, frameData);
                }
            }
            else if (string.Equals(node.Name, base.FrameData.ClosingName) && !node.IsEmptyElement)
            {
                Frame local1 = base.FrameData;
                local1.ClosingNameOutstanding++;
                this.Nodes.Add(node);
            }
            else
            {
                this.Nodes.Add(node);
            }
        }
        public override IList <IHtmlValidationError> ValidateElement(ElementNode element)
        {
            var results = new ValidationErrorCollection();

            if (!WESettings.Instance.Html.EnableAngularValidation)
            {
                return(results);
            }

            AttributeNode attr = element.Attributes.SingleOrDefault(a => a.Name.StartsWith("ng-", StringComparison.Ordinal) || a.Name.StartsWith("data-ng-", StringComparison.Ordinal));

            if (ShouldIgnore(element, attr))
            {
                return(results);
            }

            if (attr != null)
            {
                int index = element.Attributes.IndexOf(attr);
                results.AddAttributeError(element, _error, HtmlValidationErrorLocation.AttributeName, index);
            }
            else
            {
                results.Add(element, _error, HtmlValidationErrorLocation.ElementName);
            }

            return(results);
        }
        private ProblemCollection CheckForProblems(AttributeNode attribute)
        {
			if (SemanticRulesUtilities.HasAttribute<ServiceContractAttribute>(attribute))
			{
				// reset the hasUnmatchedMessageHandler flag for each new type
				hasUnmatchedMessageHandler = false;
				return base.Problems;
			}

			string action = SemanticRulesUtilities.GetAttributeValue<String>(attribute, "Action");
			if (SemanticRulesUtilities.HasAttribute<OperationContractAttribute>(attribute) &&
				!string.IsNullOrEmpty(action) &&
				 action.Equals("*", StringComparison.OrdinalIgnoreCase))
			{
				// check if we already inspected another operation with unmatched message handler
				if (hasUnmatchedMessageHandler)
				{
					Resolution resolution = base.GetResolution();
					Problem problem = new Problem(resolution, attribute.SourceContext);
					base.Problems.Add(problem);
					return base.Problems;
				}
				hasUnmatchedMessageHandler = true;
			}
            return base.Problems;
        }
Example #21
0
        protected override void Visit(SpecialNode node)
        {
            SpecialNode   item  = new SpecialNode(node.Element);
            string        name  = NameUtility.GetName(node.Element.Name);
            AttributeNode node3 = null;

            if (name != "for")
            {
                node3 = item.Element.Attributes.FirstOrDefault <AttributeNode>(attr => this.IsSpecialAttribute(node.Element, attr));
            }
            if (node3 != null)
            {
                SpecialNode node4 = this.CreateWrappingNode(node3, item.Element);
                item.Element.Attributes.Remove(node3);
                this.Nodes.Add(node4);
                base.PushFrame(node4.Body, new Frame());
            }
            this.Nodes.Add(item);
            base.PushFrame(item.Body, new Frame());
            base.Accept(node.Body);
            base.PopFrame();
            if (node3 != null)
            {
                base.PopFrame();
            }
        }
Example #22
0
        /// <summary>
        /// This is used to see if an attribute type is exposed
        /// </summary>
        /// <param name="attribute">The attribute node to check</param>
        /// <returns>True if the attribute is exposed, false if not</returns>
        public virtual bool IsExposedAttribute(AttributeNode attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            // Check whether the attribute type is exposed
            TypeNode attributeType = attribute.Type;

            if (!this.IsExposedType(attributeType))
            {
                return(false);
            }

            // Check whether expressions used to instantiate the attribute are exposed
            foreach (var expression in attribute.Expressions)
            {
                if (!this.IsExposedExpression(expression))
                {
                    return(false);
                }
            }

            // If excluding attributes, just check for ones that are required
            if (!this.IncludeAttributes)
            {
                return(attributeFilter.IsRequiredType(attributeType));
            }

            // Apply user filters to the attribute
            return(attributeFilter.IsExposedType(attributeType));
        }
Example #23
0
        public virtual bool IsExposedAttribute(AttributeNode attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            // check whether attribte type is exposed
            TypeNode attributeType = attribute.Type;

            if (!IsExposedType(attributeType))
            {
                return(false);
            }

            // check whether expressions used to instantiate attribute are exposed
            ExpressionList expressions = attribute.Expressions;

            for (int i = 0; i < expressions.Count; i++)
            {
                if (!IsExposedExpression(expressions[i]))
                {
                    return(false);
                }
            }

            // apply user filters to attribute
            return(attributeFilter.IsExposedType(attributeType));
        }
        public static bool IsItemNullabilityAttribute([NotNull] this AttributeNode attribute)
        {
            Guard.NotNull(attribute, "attribute");

            return(attribute.Type.Name.Name == "ItemNotNullAttribute" ||
                   attribute.Type.Name.Name == "ItemCanBeNullAttribute");
        }
Example #25
0
        public override AttributeNode VisitAttributeNode(AttributeNode attribute)
        {
            if (attribute == null)
            {
                return(null);
            }

            if (attribute.Type.Namespace != null && ContractNodes.ContractNamespace.Matches(attribute.Type.Namespace))
            {
                switch (attribute.Type.Name.Name)
                {
                case "ContractClassAttribute":
                case "ContractInvariantMethodAttribute":
                case "ContractClassForAttribute":
                case "ContractVerificationAttribute":
                case "ContractPublicPropertyNameAttribute":
                case "ContractArgumentValidatorAttribute":
                case "ContractAbbreviatorAttribute":
                case "ContractOptionAttribute":
                case "ContractRuntimeIgnoredAttribute":
                case "PureAttribute":
                    return(attribute);

                default:
                    return(null);
                    // Don't propagate any other attributes from System.Diagnostics.Contracts, they might be types defined only in mscorlib.contracts.dll
                }
            }

            return(base.VisitAttributeNode(attribute));
        }
 public virtual AttributeNode GetClosestMatch(AttributeNode/*!*/ nd1, AttributeList/*!*/ list1, AttributeList list2, int list1pos, ref int list2start,
   TrivialHashtable/*!*/ matchedNodes, out Differences closestDifferences, out int list2pos) {
   closestDifferences = null; list2pos = -1;
   if (list2 == null) return null;
   if (nd1 == null || list1 == null || matchedNodes == null ||  list1pos < 0 || list1pos >= list1.Count || list2start < 0 || list2start >= list2.Count) {
     Debug.Assert(false); return null;
   }
   AttributeNode closest = null;
   Differences winnerSoFar = null;
   for (int j = list2start, m = list2.Count; j < m; j++){
     AttributeNode nd2 = list2[j];
     if (list2start == j) list2start++;
     if (nd2 == null) continue;
     if (matchedNodes[nd2.UniqueKey] != null) continue;
     Differences diff = this.GetDifferences(nd1, nd2);
     if (diff == null){Debug.Assert(false); continue;}
     if (diff.Similarity <= 0.5){
       //Not a good enough match
       if (list2start == j+1) list2start--; //The next call to GetClosestMatch will start looking at list2start, so this node will be considered then
       continue; //ignore it for the rest of this call
     }
     if (winnerSoFar != null && winnerSoFar.Similarity >= diff.Similarity) continue;
     winnerSoFar = closestDifferences = diff;
     closest = nd2;
     list2pos = j;
     if (diff.NumberOfDifferences == 0) return closest; //Perfect match, no need to look for other matches
   }
   if (closest != null){
     //^ assert winnerSoFar != null;
     //closest is closer to nd1 than any other node in list2, but this is no good if some other node in list1 has a better claim on closest
     for (int i = list1pos+1, n = list1.Count; i < n; i++){
       AttributeNode nd1alt = list1[i];
       if (nd1alt == null) continue;
       if (matchedNodes[nd1alt.UniqueKey] != null) continue;
       Differences diff = this.GetDifferences(nd1alt, closest);
       if (diff == null){Debug.Assert(false); continue;}
       if (diff.Similarity <= winnerSoFar.Similarity) continue;
       //nd1alt has a better claim on closest. See if it wants closest.
       Differences diff2;
       int j, k = list2start;
       AttributeNode nd2alt = this.GetClosestMatch(nd1alt, list1, list2, i, ref k,  matchedNodes, out diff2, out j);
       if (nd2alt != closest){
         Debug.Assert(nd2alt != null && diff2 != null && diff2.Similarity >= diff.Similarity);
         continue; //nd1alt prefers nd2alt to closest, so closest is still available
       }
       //nd1alt wants closest, take it out of the running
       matchedNodes[closest.UniqueKey] = nd1alt;
       //Now that closest is out of the running, try again
       k = list2start;
       AttributeNode newClosest = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out winnerSoFar, out list2pos);
       //put closest back in the running so that the next call to this routine will pick it up
       matchedNodes[closest.UniqueKey] = closest;
       closest = newClosest;
       break;
     }
   }
   closestDifferences = winnerSoFar;
   return closest;
 }
Example #27
0
        public override AttributeNode genAttr()
        {
            AttributeNode attr = base.genAttr();

            attr.Expressions.Add(new Literal(return_type_ref, SystemTypes.Int32));
            attr.Expressions.Add(new Literal(pars, SystemTypes.Int32));
            return(addName(attr, "ProcType"));
        }
Example #28
0
 public static bool IsFragment(AttributeNode attribute)
 {
     ArgumentUtility.CheckNotNull ("attribute", attribute);
       string fragmentFullName = typeof (FragmentAttribute).FullName;
       bool isFragment = attribute.Type.FullName == fragmentFullName;
       bool isFragmentChild = attribute.Type.BaseType.FullName == fragmentFullName;
       return isFragment || isFragmentChild;
 }
Example #29
0
        public override AttributeNode genAttr()
        {
            AttributeNode attr = base.genAttr();

            attr.Expressions.Add(new Literal(var, SystemTypes.Boolean));
            attr.Expressions.Add(new Literal(type_ref, SystemTypes.Int32));
            return(addName(attr, "Parameter"));
        }
        public IEnumerable <ISuggestedAction> GetSuggestedActions(ITextView textView, ITextBuffer textBuffer, int caretPosition, ElementNode element, AttributeNode attribute, HtmlPositionType positionType)
        {
            AttributeNode src = element.GetAttribute("src");

            return(new ISuggestedAction[] {
                new HtmlBase64DecodeLightBulbAction(textView, textBuffer, element, src)
            });
        }
Example #31
0
 public static bool HasAttribute <T>(AttributeNode attribute) where T : Attribute
 {
     if (attribute == null)
     {
         return(false);
     }
     return(attribute.Type.FullName.Equals(typeof(T).FullName, StringComparison.Ordinal));
 }
Example #32
0
        public override AttributeNode genAttr()
        {
            AttributeNode attr = base.genAttr();

            attr.Expressions.Add(new Literal(elem_type_ref, SystemTypes.Int32));
            attr.Expressions.Add(new Literal(dims, SystemTypes.Int32));
            return(addName(attr, "ArrayType"));
        }
Example #33
0
        public override AttributeNode genAttr( )
        {
            AttributeNode attr = base.genAttr();

            attr.Expressions.Add(new Literal(name, SystemTypes.String));
            attr.Expressions.Add(new Literal(end_ref, SystemTypes.Int32));
            return(attr);
        }
        public WhileLoopStatementNode(ExpressionNode conditionExpression, StatementNodeBase body, AttributeNode[] attributes)
            : base(body, attributes)
        {
            if (conditionExpression == null)
                throw new ArgumentNullException("conditionExpression", "The ConditionExpression is null!");

            ConditionExpression = conditionExpression;
            AddChildren(ConditionExpression);
        }
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            if ((element.IsStyleBlock() || element.IsJavaScriptBlock()) && element.InnerRange.Length > 5)
            {
                return new ExtractToFileSmartTag(textView, textBuffer, element);
            }

            return null;
        }
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            if (element.InnerRange == null || element.GetText(element.InnerRange).Trim().Length == 0)
                return null;

            string displayText = element.Children.Count == 0 ? "Remove HTML tag" : "Remove and keep children";

            return new HtmlRemoveParentSmartTag(textView, textBuffer, element, displayText);
        }
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            if (element.GetAttribute("ng-controller") != null)
            {
                return new HtmlAngularControllerSmartTag(textView, textBuffer, element);
            }

            return null;
        }
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            if (IsEnabled(element))
            {
                return new OptimizeImageSmartTag(textView, textBuffer, element);
            }

            return null;
        }
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            if (element.IsStyleBlock() || element.IsJavaScriptBlock())
            {
                return new HtmlMinifySmartTag(textView, textBuffer, element);
            }

            return null;
        }
Example #40
0
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            if (element.GetAttribute("class") == null)
            {
                return new $safeitemname$SmartTag(textView, textBuffer, element);
            }

            return null;
        }
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            if (element.Children.Count > 0)
            {
                return new HtmlRemoveParentSmartTag(textView, textBuffer, element);
            }

            return null;
        }
Example #42
0
        public WhileLoopStatementNode While(ExpressionNode condition, StatementNodeBase body, AttributeNode[] attributes)
        {
            if (condition == null)
                ThrowHelper.ThrowArgumentNullException(() => condition);

            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            return new WhileLoopStatementNode(condition, body, attributes);
        }
Example #43
0
 public static Literal GetAttributeValue( AttributeNode attr, int index ) {
   Debug.Assert( attr != null && index >= 0 && index < attr.Expressions.Count );
   if (attr == null) return null;
   for (int i = 0, n = attr.Expressions.Count, c = 0; i < n; i++) {
     Literal lit = attr.Expressions[i] as Literal;
     if (lit != null) {
       if (c == index) return lit;
       c++;
     }
   }
   return null;
 }
        public static Uri NormalizeUrl(AttributeNode attribute)
        {
            string value = attribute.Value;

            if (value.StartsWith("//", StringComparison.Ordinal))
                value = "http:" + value;

            Uri url;
            Uri.TryCreate(value, UriKind.Absolute, out url);

            return url;
        }
 internal void AddAttribute(string name, string value, string xmlns, string prefix)
 {
     if (this.closed)
     {
         throw new InvalidOperationException(System.Transactions.SR.GetString("CannotAddToClosedDocument"));
     }
     if (this.current == null)
     {
         throw new InvalidOperationException(System.Transactions.SR.GetString("OperationInvalidOnAnEmptyDocument"));
     }
     AttributeNode item = new AttributeNode(name, prefix, xmlns, value);
     this.current.attributes.Add(item);
 }
Example #46
0
        public ForeachLoopStatementNode Foreach(string variable, TypeNameNode variableType, ExpressionNode expression, StatementNodeBase body, AttributeNode[] attributes)
        {
            if (string.IsNullOrWhiteSpace(variable))
                ThrowHelper.ThrowException("The 'variable' is blank!");
            if (expression == null)
                ThrowHelper.ThrowArgumentNullException(() => expression);
            if (body == null)
                ThrowHelper.ThrowArgumentNullException(() => body);
            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            return new ForeachLoopStatementNode(variable, variableType, expression, body, attributes);
        }
 public static Literal GetNamedAttributeValue( AttributeNode attr, Identifier name ) {
   if( attr == null ) return null;
   ExpressionList exprs = attr.Expressions;
   if( exprs == null ) return null;
   for( int i = 0, n = exprs.Count; i < n; i++ ) {
     NamedArgument na = exprs[i] as NamedArgument;
     if( na == null ) continue;
     if( na.Name.UniqueIdKey == name.UniqueIdKey ) {
       return na.Value as Literal;
     }
   }
   return null;
 }
 internal void AddAttribute(string name, string value, string xmlns, string prefix)
 {
     if (this.closed)
     {
         throw new InvalidOperationException();
     }
     if (this.current == null)
     {
         throw new InvalidOperationException();
     }
     AttributeNode node = new AttributeNode(name, prefix, value, xmlns);
     this.VerifySize(node);
     this.CurrentElement.attributes.Add(node);
 }
        public IHtmlSmartTag TryCreateSmartTag(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, int caretPosition, HtmlPositionType positionType)
        {
            AttributeNode attr = element.GetAttribute("src") ?? element.GetAttribute("href");

            if (attr == null)
                return null;

            Uri url = NormalizeUrl(attr);

            if (url == null || (!attr.Value.StartsWith("//", StringComparison.Ordinal) && !attr.Value.Contains("://")))
                return null;

            return new RemoteDownloaderSmartTag(textView, textBuffer, element, attr);
        }
        protected TypeDeclarationStatementNodeBase(string name, FormalParameterNode[] parameters, AttributeNode[] attributes)
            : base(name)
        {
            if (parameters == null)
                ThrowHelper.ThrowArgumentNullException(() => parameters);

            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            Parameters = parameters.ToList();
            Attributes = attributes.ToList();

            AddChildren(Parameters);
            AddChildren(Attributes);
        }
        /// <summary>
        /// Evaluates the rule.
        /// </summary>
        /// <param name="type">The type.</param>
		/// <param name="attribute">The attribute.</param>
		/// <param name="binding">The binding.</param>
        public override void EvaluateRule(TypeNode type, 
            AttributeNode attribute, string binding)
        {
			// for further info on Sessions and bindings, 
			// read: http://msdn2.microsoft.com/en-us/library/ms730879.aspx
			if ((SemanticRulesUtilities.GetAttributeValue<SessionMode>(attribute, "SessionMode") == SessionMode.Required &&
					IsSessionlessBinding(binding)) ||
				(SemanticRulesUtilities.GetAttributeValue<SessionMode>(attribute, "SessionMode") == SessionMode.NotAllowed &&
					IsSessionfullBinding(binding)))
			{
				Resolution resolution = base.GetResolution(type.FullName, binding);
				Problem problem = new Problem(resolution);
				base.Problems.Add(problem);
			}
        }
        public ForeachLoopStatementNode(string variable, TypeNameNode variableType, ExpressionNode expression, StatementNodeBase body, AttributeNode[] attributes)
            : base(body, attributes)
        {
            if (string.IsNullOrWhiteSpace(variable))
                ThrowHelper.ThrowException("The 'variable' is blank!");

            if (expression == null) throw new ArgumentNullException("expression", "The expression is null!");

            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            LoopVariable = new IdentifierExpressionNode(variable);
            Expression = expression;
            LoopVariableType = variableType;

            AddChildren(LoopVariable, LoopVariableType, Expression);
        }
 public override void VisitAttributeNode(AttributeNode attribute)
 {
     if (Utilities.HasAttribute<ServiceContractAttribute>(attribute) ||
         Utilities.HasAttribute<OperationContractAttribute>(attribute))
     {
         ProtectionLevel protectionLevel;
         if (Utilities.TryGetAttributeValue<ProtectionLevel>(attribute, "ProtectionLevel", out protectionLevel))
         {
             if (protectionLevel == ProtectionLevel.None)
             {
                 Resolution resolution = base.GetResolution(attribute.Type.Name.Name);
                 Problem problem = new Problem(resolution, attribute.SourceContext);
                 base.Problems.Add(problem);
             }
         }
     }
 }
        public VariableDeclarationStatementNode(string name, TypeNameNode variableType, ExpressionNode initialValue, AttributeNode[] attributes)
        {
            if (name == null)
                ThrowHelper.ThrowArgumentNullException(() => name);

            if (variableType == null)
                ThrowHelper.ThrowArgumentNullException(() => variableType);

            if (initialValue == null)
                ThrowHelper.ThrowArgumentNullException(() => initialValue);

            InitialValue = initialValue;
            Identifier = new IdentifierExpressionNode(name, null);
            VariableType = variableType;
            Attributes = attributes.ToList();

            AddChildren(Identifier, VariableType, InitialValue);
            AddChildren(Attributes);
        }
 private AttributeNode Translate(CodeAttributeDeclaration attribute){
   if (attribute == null) return null;
   AttributeNode anode = new AttributeNode();
   anode.Constructor = this.TranslateToSimpleIdentifierOrQualifiedIdentifier(attribute.Name);
   CodeAttributeArgumentCollection codeArguments = attribute.Arguments;
   if (codeArguments != null){
     int n = codeArguments.Count;
     if (n > 0){
       ExpressionList arguments = anode.Expressions = new ExpressionList(n);
       for (int i = 0; i < n; i++){
         CodeAttributeArgument arg = codeArguments[i];
         string name = arg.Name;
         Expression argValue = this.Translate(arg.Value);
         if (name == null || name.Length == 0)
           arguments.Add(argValue);
         else
           arguments.Add(new NamedArgument(Identifier.For(name), argValue));
       }
     }
   }
   return anode;
 }
        private ProblemCollection CheckForProblems(AttributeNode attribute, Member member)
        {
			if (SemanticRulesUtilities.HasAttribute<ServiceContractAttribute>(attribute))
			{
				// store state for check member analysis overload.
				hasSessionMode = SemanticRulesUtilities.HasAttribute<ServiceContractAttribute>(attribute, "SessionMode");
				if (hasSessionMode)
				{
					sessionMode = SemanticRulesUtilities.GetAttributeValue<SessionMode>(attribute, "SessionMode");
				}
				return base.Problems;
			}

			if (SemanticRulesUtilities.HasAttribute<OperationContractAttribute>(attribute) &&
				IsRuleViolated(attribute))
			{
				Resolution resolution = base.GetResolution(CustomizeDescription(attribute), member.Name.Name);
				Problem problem = new Problem(resolution, attribute.SourceContext);
				base.Problems.Add(problem);
				return base.Problems;
			}
            return base.Problems;
        }
Example #57
0
 public virtual AttributeNode VisitAttributeNode(AttributeNode attribute, AttributeNode changes, AttributeNode deletions, AttributeNode insertions){
   this.UpdateSourceContext(attribute, changes);
   if (attribute == null) return changes;      
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
       attribute.AllowMultiple = changes.AllowMultiple;
       attribute.Constructor = this.VisitExpression(attribute.Constructor, changes.Constructor, deletions.Constructor, insertions.Constructor);
       attribute.Expressions = this.VisitExpressionList(attribute.Expressions, changes.Expressions, deletions.Expressions, insertions.Expressions);
       attribute.Target = changes.Target;
     }
   }else if (deletions != null)
     return null;
   return attribute;
 }
Example #58
0
 protected override void Visit(AttributeNode attributeNode)
 {
 }
Example #59
0
 public virtual AttributeNode VisitAttributeNode(AttributeNode attribute){
   if (attribute == null) return null;      
   attribute.Constructor = this.VisitAttributeConstructor(attribute);
   attribute.Expressions = this.VisitExpressionList(attribute.Expressions);
   return attribute;
 }
    public virtual Differences VisitAttributeNode(AttributeNode attribute1, AttributeNode attribute2){
      Differences differences = new Differences(attribute1, attribute2);
      if (attribute1 == null || attribute2 == null){
        if (attribute1 != attribute2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      AttributeNode changes = (AttributeNode)attribute2.Clone();
      AttributeNode deletions = (AttributeNode)attribute2.Clone();
      AttributeNode insertions = (AttributeNode)attribute2.Clone();

      if (attribute1.AllowMultiple == attribute2.AllowMultiple) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      Differences diff = this.VisitExpression(attribute1.Constructor, attribute2.Constructor);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Constructor = diff.Changes as Expression;
      deletions.Constructor = diff.Deletions as Expression;
      insertions.Constructor = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Constructor && diff.Deletions == deletions.Constructor && diff.Insertions == insertions.Constructor);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      ExpressionList exprChanges, exprDeletions, exprInsertions;
      diff = this.VisitExpressionList(attribute1.Expressions, attribute2.Expressions, out exprChanges, out exprDeletions, out exprInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Expressions = exprChanges;
      deletions.Expressions = exprDeletions;
      insertions.Expressions = exprInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (attribute1.Target == attribute2.Target) differences.NumberOfSimilarities++; else differences.NumberOfDifferences++;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }