Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Highlight inactive conditional attributes.
Browse files Browse the repository at this point in the history
Highlight type name in constructor/destructor declaration.
Handle InvalidCastException when reading a corrupted serialized project content.
  • Loading branch information
dgrunwald committed Jul 28, 2012
1 parent a25ebfe commit 8ba973b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public HighlightedLine HighlightLine(int lineNumber)
}
this.line = null;
this.resolver = null;
Debug.WriteLine("Semantic highlighting for line {0} - added {1} sections", lineNumber, line.Sections.Count);
//Debug.WriteLine("Semantic highlighting for line {0} - added {1} sections", lineNumber, line.Sections.Count);
if (textEditor.Document.Version != null) {
cachedLines.Add(new CachedLine(line, textEditor.Document.Version));
}
Expand Down Expand Up @@ -438,6 +438,36 @@ public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)
}
}

public override void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration)
{
HandleConstructorOrDestructor(constructorDeclaration);
}

public override void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration)
{
HandleConstructorOrDestructor(destructorDeclaration);
}

void HandleConstructorOrDestructor(AstNode constructorDeclaration)
{
for (AstNode child = constructorDeclaration.FirstChild; child != null; child = child.NextSibling) {
if (child.StartLocation.Line <= lineNumber && child.EndLocation.Line >= lineNumber) {
if (child.Role == Roles.Identifier) {
// child == constructorDeclaration.NameToken
var currentTypeDef = resolver.GetResolverStateBefore(constructorDeclaration).CurrentTypeDefinition;
if (currentTypeDef != null && ((Identifier)child).Name == currentTypeDef.Name) {
if (currentTypeDef.IsReferenceType == true)
Colorize(child, referenceTypeColor);
else if (currentTypeDef.IsReferenceType == false)
Colorize(child, valueTypeColor);
}
} else {
child.AcceptVisitor(this);
}
}
}
}

public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
{
// Type declarations often contain #if directives, so we must make sure
Expand Down Expand Up @@ -499,6 +529,16 @@ public override void VisitComment(Comment comment)
Colorize(comment, inactiveCodeColor);
}
}

public override void VisitAttribute(ICSharpCode.NRefactory.CSharp.Attribute attribute)
{
ITypeDefinition attrDef = resolver.Resolve(attribute.Type).Type.GetDefinition();
if (attrDef != null && IsInactiveConditional(attrDef.Attributes)) {
Colorize(attribute, inactiveCodeColor);
return;
}
VisitChildren(attribute);
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ static IProjectContent TryReadFromCache(string cacheFileName)
} catch (SerializationException ex) {
LoggingService.Warn(ex);
return null;
} catch (InvalidCastException ex) {
LoggingService.Warn(ex);
return null;
}
}

Expand Down

0 comments on commit 8ba973b

Please sign in to comment.