~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.VB/Ast/General/AttributedNode.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using System.Linq;
 
7
 
 
8
namespace ICSharpCode.NRefactory.VB.Ast
 
9
{
 
10
        public abstract class AttributedNode : AstNode
 
11
        {
 
12
                public AstNodeCollection<AttributeBlock> Attributes {
 
13
                        get { return GetChildrenByRole(AttributeBlock.AttributeBlockRole); }
 
14
                }
 
15
                
 
16
                public static readonly Role<VBModifierToken> ModifierRole = new Role<VBModifierToken>("Modifier");
 
17
                
 
18
                public Modifiers Modifiers {
 
19
                        get { return GetModifiers(this); }
 
20
                        set { SetModifiers(this, value); }
 
21
                }
 
22
                
 
23
                public AstNodeCollection<VBModifierToken> ModifierTokens {
 
24
                        get { return GetChildrenByRole (ModifierRole); }
 
25
                }
 
26
                
 
27
                internal static Modifiers GetModifiers(AstNode node)
 
28
                {
 
29
                        Modifiers m = 0;
 
30
                        foreach (VBModifierToken t in node.GetChildrenByRole (ModifierRole)) {
 
31
                                m |= t.Modifier;
 
32
                        }
 
33
                        return m;
 
34
                }
 
35
                
 
36
                internal static void SetModifiers(AstNode node, Modifiers newValue)
 
37
                {
 
38
                        Modifiers oldValue = GetModifiers(node);
 
39
                        AstNode insertionPos = node.GetChildrenByRole(Attribute.AttributeRole).LastOrDefault();
 
40
                        foreach (Modifiers m in VBModifierToken.AllModifiers) {
 
41
                                if ((m & newValue) != 0) {
 
42
                                        if ((m & oldValue) == 0) {
 
43
                                                // Modifier was added
 
44
                                                var newToken = new VBModifierToken(TextLocation.Empty, m);
 
45
                                                node.InsertChildAfter(insertionPos, newToken, ModifierRole);
 
46
                                                insertionPos = newToken;
 
47
                                        } else {
 
48
                                                // Modifier already exists
 
49
                                                insertionPos = node.GetChildrenByRole(ModifierRole).First(t => t.Modifier == m);
 
50
                                        }
 
51
                                } else {
 
52
                                        if ((m & oldValue) != 0) {
 
53
                                                // Modifier was removed
 
54
                                                node.GetChildrenByRole (ModifierRole).First(t => t.Modifier == m).Remove();
 
55
                                        }
 
56
                                }
 
57
                        }
 
58
                }
 
59
                
 
60
                protected bool MatchAttributesAndModifiers(AttributedNode o, PatternMatching.Match match)
 
61
                {
 
62
                        return (this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch(o.Attributes, match);
 
63
                }
 
64
        }
 
65
        
 
66
 
 
67
}