Skip to content

Commit

Permalink
Merge branch 'next' into ResolveParameterlessDefaultMemberAccesses
Browse files Browse the repository at this point in the history
  • Loading branch information
MDoerner committed Aug 24, 2019
2 parents 617b27f + 4164774 commit 6aa489b
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 2,593 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -189,3 +189,4 @@ Rubberduck.CodeAnalysis.xml

#Gradle
/.gradle/
/Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.xml
203 changes: 102 additions & 101 deletions Rubberduck.CodeAnalysis/Properties/CodeInspectionDefaults.Designer.cs

Large diffs are not rendered by default.

Expand Up @@ -18,6 +18,7 @@
<CodeInspection Name="MissingAttributeInspection" Severity="Warning" InspectionType="RubberduckOpportunities" />
<CodeInspection Name="AttributeOutOfSyncInspection" Severity="Warning" InspectionType="RubberduckOpportunities" />
<CodeInspection Name="MissingAnnotationArgumentInspection" Severity="Error" InspectionType="CodeQualityIssues" />
<CodeInspection Name="MissingMemberAnnotationInspection" Severity="Error" InspectionType="RubberduckOpportunities" />
<CodeInspection Name="ModuleScopeDimKeywordInspection" Severity="Suggestion" InspectionType="LanguageOpportunities" />
<CodeInspection Name="MultilineParameterInspection" Severity="Suggestion" InspectionType="MaintainabilityAndReadabilityIssues" />
<CodeInspection Name="MultipleDeclarationsInspection" Severity="Warning" InspectionType="MaintainabilityAndReadabilityIssues" />
Expand Down
2,468 changes: 0 additions & 2,468 deletions Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.xml

This file was deleted.

4 changes: 3 additions & 1 deletion Rubberduck.Parsing/Annotations/AnnotationType.cs
Expand Up @@ -72,7 +72,9 @@ public enum AnnotationType
ModuleAttribute = 1 << 20 | Attribute | ModuleAnnotation,
MemberAttribute = 1 << 21 | Attribute | MemberAnnotation | VariableAnnotation,
[FlexibleAttributeValueAnnotation("VB_VarDescription", 1)]
VariableDescription = 1 << 13 | Attribute | VariableAnnotation
VariableDescription = 1 << 13 | Attribute | VariableAnnotation,
[FlexibleAttributeValueAnnotation("VB_ProcData.VB_Invoke_Func", 1)]
ExcelHotKey = 1 << 16 | Attribute | MemberAnnotation
}

[AttributeUsage(AttributeTargets.Field)]
Expand Down
5 changes: 5 additions & 0 deletions Rubberduck.Parsing/Annotations/AttributeAnnotationProvider.cs
Expand Up @@ -33,6 +33,11 @@ public class AttributeAnnotationProvider : IAttributeAnnotationProvider
var flexibleValueAttributeAnnotation = FirstMatchingFlexibleAttributeValueAnnotation(annotationTypes, attributeName, attributeValues.Count);
if (flexibleValueAttributeAnnotation != default)
{
// FIXME special cased bodge for ExcelHotKeyAnnotation to deal with the value transformation:
if (flexibleValueAttributeAnnotation == AnnotationType.ExcelHotKey)
{
return (flexibleValueAttributeAnnotation, attributeValues.Select(keySpec => '"' + keySpec.Substring(1, 1) + '"').ToList());
}
return (flexibleValueAttributeAnnotation, attributeValues);
}

Expand Down
23 changes: 23 additions & 0 deletions Rubberduck.Parsing/Annotations/ExcelHotKeyAnnotation.cs
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Parsing.Grammar;
using Rubberduck.VBEditor;

namespace Rubberduck.Parsing.Annotations
{
public sealed class ExcelHotKeyAnnotation : FlexibleAttributeValueAnnotationBase
{
public ExcelHotKeyAnnotation(QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable<string> annotationParameterValues) :
base(AnnotationType.ExcelHotKey, qualifiedSelection, context, GetHotKeyAttributeValue(annotationParameterValues))
{ }

private static IEnumerable<string> GetHotKeyAttributeValue(IEnumerable<string> parameters) =>
parameters.Take(1).Select(StripStringLiteralQuotes).Select(v => @"""" + v[0] + @"\n14""").ToList();

private static string StripStringLiteralQuotes(string value) =>
value.StartsWith("\"") && value.EndsWith("\"") && value.Length > 2
? value.Substring(1, value.Length - 2)
: value;
}
}
Expand Up @@ -8,26 +8,19 @@ namespace Rubberduck.Parsing.Annotations
{
public abstract class FlexibleAttributeValueAnnotationBase : AnnotationBase, IAttributeAnnotation
{
protected FlexibleAttributeValueAnnotationBase(AnnotationType annotationType, QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable<string> parameters)
public string Attribute { get; }
public IReadOnlyList<string> AttributeValues { get; }

protected FlexibleAttributeValueAnnotationBase(AnnotationType annotationType, QualifiedSelection qualifiedSelection, VBAParser.AnnotationContext context, IEnumerable<string> attributeValues)
:base(annotationType, qualifiedSelection, context)
{
var flexibleAttributeValueInfo = FlexibleAttributeValueInfo(annotationType);

if (flexibleAttributeValueInfo == null)
{
Attribute = string.Empty;
AttributeValues = new List<string>();
return;
}

Attribute = flexibleAttributeValueInfo.Value.attribute;
AttributeValues = parameters?.Take(flexibleAttributeValueInfo.Value.numberOfValues).ToList() ?? new List<string>();
Attribute = flexibleAttributeValueInfo.attribute;
AttributeValues = attributeValues?.Take(flexibleAttributeValueInfo.numberOfValues).ToList() ?? new List<string>();
}

public string Attribute { get; }
public IReadOnlyList<string> AttributeValues { get; }

private static (string attribute, int numberOfValues)? FlexibleAttributeValueInfo(AnnotationType annotationType)
private static (string attribute, int numberOfValues) FlexibleAttributeValueInfo(AnnotationType annotationType)
{
var type = annotationType.GetType();
var name = Enum.GetName(type, annotationType);
Expand All @@ -38,7 +31,7 @@ private static (string attribute, int numberOfValues)? FlexibleAttributeValueInf

if (attribute == null)
{
return null;
return ("", 0);
}

return (attribute.AttributeName, attribute.NumberOfParameters);
Expand Down
Expand Up @@ -33,6 +33,7 @@ public VBAParserAnnotationFactory()
_creators.Add(AnnotationType.ModuleAttribute.ToString().ToUpperInvariant(), typeof(ModuleAttributeAnnotation));
_creators.Add(AnnotationType.MemberAttribute.ToString().ToUpperInvariant(), typeof(MemberAttributeAnnotation));
_creators.Add(AnnotationType.ModuleDescription.ToString().ToUpperInvariant(), typeof(ModuleDescriptionAnnotation));
_creators.Add(AnnotationType.ExcelHotKey.ToString().ToUpperInvariant(), typeof(ExcelHotKeyAnnotation));
}

public IAnnotation Create(VBAParser.AnnotationContext context, QualifiedSelection qualifiedSelection)
Expand Down
Expand Up @@ -5,6 +5,7 @@
namespace RubberduckTests.Annotations
{
[TestFixture]
[Category("Annotations")]
public class AttributeAnnotationProviderTests
{
[Test]
Expand Down Expand Up @@ -56,13 +57,14 @@ public void ModuleAttributeAnnotationReturnsSpecializedAnnotationsWhereApplicabl
AssertEqual(expectedValues, actualValues);
}

[TestCase("VB_ProcData.VB_Invoke_Func", "\"A\n14\"", AnnotationType.ExcelHotKey, "\"A\"")]
[TestCase("VB_Description", "\"SomeDescription\"", AnnotationType.Description, "\"SomeDescription\"")]
[TestCase("VB_VarDescription", "\"SomeDescription\"", AnnotationType.VariableDescription, "\"SomeDescription\"")]
[TestCase("VB_UserMemId", "0", AnnotationType.DefaultMember)]
[TestCase("VB_UserMemId", "-4", AnnotationType.Enumerator)]
public void MemberAttributeAnnotationReturnsSpecializedAnnotationsWhereApplicable(string attributeName, string annotationValue, AnnotationType expectedAnnotationType, string expectedValue = null)
public void MemberAttributeAnnotationReturnsSpecializedAnnotationsWhereApplicable(string attributeName, string attributeValue, AnnotationType expectedAnnotationType, string expectedValue = null)
{
var attributeValues = new List<string> { annotationValue };
var attributeValues = new List<string> { attributeValue };
var expectedValues = expectedValue != null
? new List<string> { expectedValue }
: new List<string>();
Expand Down
18 changes: 12 additions & 6 deletions docs/Attributions.md
Expand Up @@ -4,21 +4,17 @@

### [ANTLR](http://www.antlr.org/)

As of v1.2, Rubberduck is empowered by the awesomeness of ANTLR.

> **What is ANTLR?**
Since v1.2, tokenizing and parsing the VBA code is left to the parsing masters behind Antlr. We write the language's grammatical/syntactical rules into a file that Antlr processes to generate a lexer that can turn a string into a stream of tokens, a parser that turns that stream into a tree structure Rubberduck can work with. Everything starts with Antlr.

> *ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build and walk parse trees.*
We're not doing half of what we could be doing with this amazing tool. Try it, see for yourself!

### [AvalonEdit](http://avalonedit.net)

Source code looks a lot better with syntax highlighting, and AvalonEdit excels at it.

> AvalonEdit is a WPF-based text editor component. It was written by [Daniel Grunwald](https://github.com/dgrunwald) for the [SharpDevelop](http://www.icsharpcode.net/OpenSource/SD/) IDE. Starting with version 5.0, AvalonEdit is released under the [MIT license](http://opensource.org/licenses/MIT).
We're currently only using a tiny bit of this code editor's functionality (more to come!).


### [EasyHook](http://easyhook.github.io/index.html)

Expand All @@ -34,6 +30,16 @@ This library makes localizing WPF applications at runtime using resx files a bre

> Licensed under [The Code Project Open License](http://www.codeproject.com/info/cpol10.aspx) with the [author's permission](http://www.codeproject.com/Messages/5272045/Re-License.aspx) to re-release under the GPLv3.
### [Moq](https://github.com/moq)

Moq has always been powering Rubberduck's own unit test mocks, but as of v2.5 our VBA unit testing API includes a wrapper that basically lets you use Moq for your VBA unit tests, to configure a mock implementation of any class or interface your VBA code might depend on.

> **What is ANTLR?**
> *ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build and walk parse trees.*
We're not doing half of what we could be doing with this amazing tool. Try it, see for yourself!

## Icons

We didn't come up with these icons ourselves! Here's who did what:
Expand Down

0 comments on commit 6aa489b

Please sign in to comment.