Browse Source

Moved some roles to the Roles class.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
6a0a96ce31
  1. 5
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/AttributeSection.cs
  2. 12
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Constraint.cs
  3. 5
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeDeclaration.cs
  4. 7
      ICSharpCode.NRefactory.CSharp/Ast/Roles.cs
  5. 2
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  6. 2
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
  7. 42
      ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
  8. 52
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  9. 4
      ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs

5
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/AttributeSection.cs

@ -81,9 +81,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -81,9 +81,6 @@ namespace ICSharpCode.NRefactory.CSharp
}
#endregion
public static readonly Role<Attribute> AttributeRole = new Role<Attribute>("Attribute");
public static readonly Role<CSharpTokenNode> TargetRole = new Role<CSharpTokenNode>("Target", CSharpTokenNode.Null);
public override NodeType NodeType {
get {
return NodeType.Unknown;
@ -113,7 +110,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -113,7 +110,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
public AstNodeCollection<Attribute> Attributes {
get { return base.GetChildrenByRole (AttributeRole); }
get { return base.GetChildrenByRole (Roles.Attribute); }
}
public CSharpTokenNode RBracketToken {

12
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/Constraint.cs

@ -36,11 +36,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -36,11 +36,6 @@ namespace ICSharpCode.NRefactory.CSharp
/// </remarks>
public class Constraint : AstNode
{
public readonly static TokenRole WhereKeywordRole = new TokenRole ("where");
public readonly static TokenRole ColonRole = TypeDeclaration.ColonRole;
public readonly static Role<AstType> BaseTypeRole = TypeDeclaration.BaseTypeRole;
public readonly static Role<SimpleType> TypeParameterRole = new Role<SimpleType> ("TypeParameter", SimpleType.Null);
public override NodeType NodeType {
get {
return NodeType.Unknown;
@ -49,15 +44,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -49,15 +44,16 @@ namespace ICSharpCode.NRefactory.CSharp
public SimpleType TypeParameter {
get {
return GetChildByRole (TypeParameterRole);
return GetChildByRole (Roles.ConstraintTypeParameter);
}
set {
SetChildByRole(TypeParameterRole, value);
SetChildByRole(Roles.ConstraintTypeParameter, value);
}
}
public AstNodeCollection<AstType> BaseTypes {
get { return GetChildrenByRole (BaseTypeRole); }
get {
return GetChildrenByRole(Roles.BaseType); }
}
public override void AcceptVisitor (IAstVisitor visitor)

5
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TypeDeclaration.cs

@ -48,8 +48,6 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,8 +48,6 @@ namespace ICSharpCode.NRefactory.CSharp
public static readonly TokenRole StructKeywordRole = new TokenRole ("struct");
public static readonly TokenRole ClassKeywordRole = new TokenRole ("class");
public readonly static TokenRole ColonRole = Roles.Colon;
public readonly static Role<AstType> BaseTypeRole = new Role<AstType>("BaseType", AstType.Null);
public readonly static Role<EntityDeclaration> MemberRole = new Role<EntityDeclaration>("Member");
public override NodeType NodeType {
@ -70,7 +68,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -70,7 +68,8 @@ namespace ICSharpCode.NRefactory.CSharp
}
public AstNodeCollection<AstType> BaseTypes {
get { return GetChildrenByRole (BaseTypeRole); }
get {
return GetChildrenByRole(Roles.BaseType); }
}
public AstNodeCollection<Constraint> Constraints {

7
ICSharpCode.NRefactory.CSharp/Ast/Roles.cs

@ -71,6 +71,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,6 +71,13 @@ namespace ICSharpCode.NRefactory.CSharp
public static readonly Role<PreProcessorDirective> PreProcessorDirective = new Role<PreProcessorDirective> ("PreProcessorDirective");
public static readonly Role<ErrorNode> Error = new Role<ErrorNode> ("Error");
public readonly static Role<AstType> BaseType = new Role<AstType> ("BaseType", AstType.Null);
public static readonly Role<Attribute> Attribute = new Role<Attribute> ("Attribute");
public static readonly Role<CSharpTokenNode> AttributeTargetRole = new Role<CSharpTokenNode> ("AttributeTarget", CSharpTokenNode.Null);
public readonly static TokenRole WhereKeyword = new TokenRole ("where");
public readonly static Role<SimpleType> ConstraintTypeParameter = new Role<SimpleType> ("TypeParameter", SimpleType.Null);
}
}

2
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

@ -510,7 +510,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -510,7 +510,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
// insert target type into compilation unit, to respect the
attr.Remove ();
var node = Unit.GetNodeAt (location) ?? Unit;
node.AddChild (attr, AttributeSection.AttributeRole);
node.AddChild (attr, Roles.Attribute);
return new ExpressionResult ((AstNode)attr, Unit);
}
}

2
ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

@ -339,6 +339,8 @@ @@ -339,6 +339,8 @@
<Properties>
<Policies>
<TextStylePolicy TabWidth="4" EolMarker="Unix" inheritsSet="Mono" inheritsScope="text/plain" scope="text/plain" />
<TextStylePolicy FileWidth="120" TabWidth="4" EolMarker="Unix" inheritsSet="Mono" inheritsScope="text/plain" scope="text/x-csharp" />
<CSharpFormattingPolicy inheritsSet="1TBS" inheritsScope="text/x-csharp" scope="text/x-csharp" />
</Policies>
</Properties>
</MonoDevelop>

42
ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -1364,7 +1364,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1364,7 +1364,7 @@ namespace ICSharpCode.NRefactory.CSharp
StartNode (attributeSection);
WriteToken (Roles.LBracket);
if (!string.IsNullOrEmpty (attributeSection.AttributeTarget)) {
WriteToken (attributeSection.AttributeTarget, AttributeSection.TargetRole);
WriteToken (attributeSection.AttributeTarget, Roles.AttributeTargetRole);
WriteToken (Roles.Colon);
Space ();
}
@ -1410,35 +1410,35 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1410,35 +1410,35 @@ namespace ICSharpCode.NRefactory.CSharp
EndNode (namespaceDeclaration);
}
public void VisitTypeDeclaration (TypeDeclaration typeDeclaration)
public void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
StartNode (typeDeclaration);
WriteAttributes (typeDeclaration.Attributes);
WriteModifiers (typeDeclaration.ModifierTokens);
StartNode(typeDeclaration);
WriteAttributes(typeDeclaration.Attributes);
WriteModifiers(typeDeclaration.ModifierTokens);
BraceStyle braceStyle;
switch (typeDeclaration.ClassType) {
case ClassType.Enum:
WriteKeyword (TypeDeclaration.EnumKeywordRole);
WriteKeyword(TypeDeclaration.EnumKeywordRole);
braceStyle = policy.EnumBraceStyle;
break;
case ClassType.Interface:
WriteKeyword (TypeDeclaration.InterfaceKeywordRole);
WriteKeyword(TypeDeclaration.InterfaceKeywordRole);
braceStyle = policy.InterfaceBraceStyle;
break;
case ClassType.Struct:
WriteKeyword (TypeDeclaration.StructKeywordRole);
WriteKeyword(TypeDeclaration.StructKeywordRole);
braceStyle = policy.StructBraceStyle;
break;
default:
WriteKeyword (TypeDeclaration.ClassKeywordRole);
WriteKeyword(TypeDeclaration.ClassKeywordRole);
braceStyle = policy.ClassBraceStyle;
break;
}
WriteIdentifier (typeDeclaration.Name);
WriteTypeParameters (typeDeclaration.TypeParameters);
if (typeDeclaration.BaseTypes.Any ()) {
Space ();
WriteToken (TypeDeclaration.ColonRole);
WriteIdentifier(typeDeclaration.Name);
WriteTypeParameters(typeDeclaration.TypeParameters);
if (typeDeclaration.BaseTypes.Any()) {
Space();
WriteToken(Roles.Colon);
Space ();
WriteCommaSeparatedList (typeDeclaration.BaseTypes);
}
@ -2338,14 +2338,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2338,14 +2338,14 @@ namespace ICSharpCode.NRefactory.CSharp
EndNode (typeParameterDeclaration);
}
public void VisitConstraint (Constraint constraint)
public void VisitConstraint(Constraint constraint)
{
StartNode (constraint);
Space ();
WriteKeyword (Constraint.WhereKeywordRole);
WriteIdentifier (constraint.TypeParameter.Identifier);
Space ();
WriteToken (Constraint.ColonRole);
StartNode(constraint);
Space();
WriteKeyword(Roles.WhereKeyword);
WriteIdentifier(constraint.TypeParameter.Identifier);
Space();
WriteToken(Roles.Colon);
Space ();
WriteCommaSeparatedList (constraint.BaseTypes);
EndNode (constraint);

52
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -334,7 +334,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -334,7 +334,7 @@ namespace ICSharpCode.NRefactory.CSharp
}
foreach (var attr in GetAttributes (optAttributes)) {
result.AddChild (attr, AttributeSection.AttributeRole);
result.AddChild (attr, Roles.Attribute);
}
// optional comma
if (loc != null && pos < loc.Count - 1 && !loc [pos].Equals (loc [pos + 1]))
@ -481,14 +481,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -481,14 +481,14 @@ namespace ICSharpCode.NRefactory.CSharp
Stack<TypeDeclaration> typeStack = new Stack<TypeDeclaration> ();
public override void Visit (Class c)
public override void Visit(Class c)
{
TypeDeclaration newType = new TypeDeclaration ();
newType.ClassType = ClassType.Class;
AddAttributeSection (newType, c);
AddAttributeSection(newType, c);
var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newType, location);
var location = LocationsBag.GetMemberLocation(c);
AddModifiers(newType, location);
int curLoc = 0;
if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), TypeDeclaration.ClassKeywordRole);
@ -503,7 +503,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -503,7 +503,7 @@ namespace ICSharpCode.NRefactory.CSharp
var commaLocations = LocationsBag.GetLocations (c.TypeBaseExpressions);
int i = 0;
foreach (var baseTypes in c.TypeBaseExpressions) {
newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole);
newType.AddChild (ConvertToType (baseTypes), Roles.BaseType);
if (commaLocations != null && i < commaLocations.Count) {
newType.AddChild (new CSharpTokenNode (Convert (commaLocations [i])), Roles.Comma);
i++;
@ -532,13 +532,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -532,13 +532,13 @@ namespace ICSharpCode.NRefactory.CSharp
AddType (newType);
}
public override void Visit (Struct s)
public override void Visit(Struct s)
{
TypeDeclaration newType = new TypeDeclaration ();
newType.ClassType = ClassType.Struct;
AddAttributeSection (newType, s);
var location = LocationsBag.GetMemberLocation (s);
AddModifiers (newType, location);
AddAttributeSection(newType, s);
var location = LocationsBag.GetMemberLocation(s);
AddModifiers(newType, location);
int curLoc = 0;
if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), TypeDeclaration.StructKeywordRole);
@ -551,7 +551,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -551,7 +551,7 @@ namespace ICSharpCode.NRefactory.CSharp
var commaLocations = LocationsBag.GetLocations (s.TypeBaseExpressions);
int i = 0;
foreach (var baseTypes in s.TypeBaseExpressions) {
newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole);
newType.AddChild (ConvertToType (baseTypes), Roles.BaseType);
if (commaLocations != null && i < commaLocations.Count) {
newType.AddChild (new CSharpTokenNode (Convert (commaLocations [i])), Roles.Comma);
i++;
@ -577,13 +577,13 @@ namespace ICSharpCode.NRefactory.CSharp @@ -577,13 +577,13 @@ namespace ICSharpCode.NRefactory.CSharp
AddType (newType);
}
public override void Visit (Interface i)
public override void Visit(Interface i)
{
TypeDeclaration newType = new TypeDeclaration ();
newType.ClassType = ClassType.Interface;
AddAttributeSection (newType, i);
var location = LocationsBag.GetMemberLocation (i);
AddModifiers (newType, location);
AddAttributeSection(newType, i);
var location = LocationsBag.GetMemberLocation(i);
AddModifiers(newType, location);
int curLoc = 0;
if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), TypeDeclaration.InterfaceKeywordRole);
@ -596,7 +596,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -596,7 +596,7 @@ namespace ICSharpCode.NRefactory.CSharp
var commaLocations = LocationsBag.GetLocations (i.TypeBaseExpressions);
int j = 0;
foreach (var baseTypes in i.TypeBaseExpressions) {
newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole);
newType.AddChild (ConvertToType (baseTypes), Roles.BaseType);
if (commaLocations != null && j < commaLocations.Count) {
newType.AddChild (new CSharpTokenNode (Convert (commaLocations [j])), Roles.Comma);
j++;
@ -666,14 +666,14 @@ namespace ICSharpCode.NRefactory.CSharp @@ -666,14 +666,14 @@ namespace ICSharpCode.NRefactory.CSharp
}
}
public override void Visit (Mono.CSharp.Enum e)
public override void Visit(Mono.CSharp.Enum e)
{
TypeDeclaration newType = new TypeDeclaration ();
AddAttributeSection (newType, e);
AddAttributeSection(newType, e);
newType.ClassType = ClassType.Enum;
var location = LocationsBag.GetMemberLocation (e);
var location = LocationsBag.GetMemberLocation(e);
AddModifiers (newType, location);
AddModifiers(newType, location);
int curLoc = 0;
if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), TypeDeclaration.EnumKeywordRole);
@ -682,7 +682,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -682,7 +682,7 @@ namespace ICSharpCode.NRefactory.CSharp
if (e.BaseTypeExpression != null) {
if (location != null && curLoc < location.Count)
newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++])), Roles.Colon);
newType.AddChild (ConvertToType (e.BaseTypeExpression), TypeDeclaration.BaseTypeRole);
newType.AddChild (ConvertToType (e.BaseTypeExpression), Roles.BaseType);
}
if (location != null && curLoc < location.Count)
@ -2557,7 +2557,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2557,7 +2557,7 @@ namespace ICSharpCode.NRefactory.CSharp
parent.AddChild (new CSharpTokenNode (Convert (chevronLocs [chevronLocs.Count - 1])), Roles.RChevron);
}
void AddConstraints (AstNode parent, TypeParameters d)
void AddConstraints(AstNode parent, TypeParameters d)
{
if (d == null)
return;
@ -2570,15 +2570,15 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2570,15 +2570,15 @@ namespace ICSharpCode.NRefactory.CSharp
continue;
var location = LocationsBag.GetLocations (c);
var constraint = new Constraint ();
constraint.AddChild (new CSharpTokenNode (Convert (c.Location)), Constraint.WhereKeywordRole);
constraint.AddChild (new SimpleType (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location))), Constraint.TypeParameterRole);
constraint.AddChild (new CSharpTokenNode (Convert (c.Location)), Roles.WhereKeyword);
constraint.AddChild (new SimpleType (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
if (location != null)
constraint.AddChild (new CSharpTokenNode (Convert (location [0])), Constraint.ColonRole);
constraint.AddChild (new CSharpTokenNode (Convert (location [0])), Roles.Colon);
var commaLocs = LocationsBag.GetLocations (c.ConstraintExpressions);
int curComma = 0;
if (c.ConstraintExpressions != null) {
foreach (var expr in c.ConstraintExpressions) {
constraint.AddChild (ConvertToType (expr), Constraint.BaseTypeRole);
constraint.AddChild (ConvertToType (expr), Roles.BaseType);
if (commaLocs != null && curComma < commaLocs.Count)
constraint.AddChild (new CSharpTokenNode (Convert (commaLocs [curComma++])), Roles.Comma);
}

4
ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs

@ -2979,7 +2979,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -2979,7 +2979,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
if (!resolverEnabled)
return null;
KnownTypeCode typeCode = primitiveType.KnownTypeCode;
if (typeCode == KnownTypeCode.None && primitiveType.Parent is Constraint && primitiveType.Role == Constraint.BaseTypeRole) {
if (typeCode == KnownTypeCode.None && primitiveType.Parent is Constraint && primitiveType.Role == Roles.BaseType) {
switch (primitiveType.Keyword) {
case "class":
case "struct":
@ -3005,7 +3005,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -3005,7 +3005,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
SimpleNameLookupMode lookupMode = SimpleNameLookupMode.Type;
if (outermostType.Parent is UsingDeclaration || outermostType.Parent is UsingAliasDeclaration) {
lookupMode = SimpleNameLookupMode.TypeInUsingDeclaration;
} else if (outermostType.Parent is TypeDeclaration && outermostType.Role == TypeDeclaration.BaseTypeRole) {
} else if (outermostType.Parent is TypeDeclaration && outermostType.Role == Roles.BaseType) {
lookupMode = SimpleNameLookupMode.BaseTypeReference;
}

Loading…
Cancel
Save