Skip to content

Commit

Permalink
Merge 3e412aa into d6b0835
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder authored Jan 19, 2025
2 parents d6b0835 + 3e412aa commit a84e36f
Show file tree
Hide file tree
Showing 143 changed files with 1,734 additions and 1,216 deletions.
11 changes: 10 additions & 1 deletion Rubberduck.CodeAnalysis/CodeAnalysisUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Rubberduck.CodeAnalysis/CodeAnalysisUI.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,7 @@
<data name="CodeInspectionSettingsPage_FilterBySeverity" xml:space="preserve">
<value>Sévérité:</value>
</data>
<data name="CodeInspectionSettingsPage_Misc_IgnoreFormControlHungarianNotation" xml:space="preserve">
<value>Ignorer la notation hongroise pour les contrôles des UserForm</value>
</data>
</root>
143 changes: 83 additions & 60 deletions Rubberduck.CodeAnalysis/CodeAnalysisUI.resx
Original file line number Diff line number Diff line change
@@ -1,76 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
Expand All @@ -89,13 +109,13 @@
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CodeInspectionResults_Type" xml:space="preserve">
<value>Type</value>
Expand Down Expand Up @@ -245,4 +265,7 @@
<data name="CodeInspectionSettingsPage_FilterBySeverity" xml:space="preserve">
<value>Severity:</value>
</data>
<data name="CodeInspectionSettingsPage_Misc_IgnoreFormControlHungarianNotation" xml:space="preserve">
<value>Ignore Hungarian Notation for UserForm controls</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Rubberduck.CodeAnalysis.Inspections.Results;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Parsing.VBA.DeclarationCaching;
using Rubberduck.VBEditor;
using System.Collections.Generic;
using System.Linq;

namespace Rubberduck.CodeAnalysis.Inspections.Abstract
{
/// <summary>
/// An inspection that flags invalid annotation comments.
/// </summary>
internal abstract class InvalidAnnotationInspectionBase : InspectionBase
{
protected InvalidAnnotationInspectionBase(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider) { }

protected QualifiedContext Context(IParseTreeAnnotation pta) =>
new QualifiedContext(pta.QualifiedSelection.QualifiedName, pta.Context);

protected sealed override IEnumerable<IInspectionResult> DoGetInspectionResults(DeclarationFinder finder)
{
return finder.UserDeclarations(DeclarationType.Module)
.Where(module => module != null)
.SelectMany(module => DoGetInspectionResults(module.QualifiedModuleName, finder));
}

protected IInspectionResult InspectionResult(IParseTreeAnnotation pta) =>
new QualifiedContextInspectionResult(this, ResultDescription(pta), Context(pta));

/// <summary>
/// Gets all invalid annotations covered by this inspection.
/// </summary>
/// <param name="annotations">All user code annotations.</param>
/// <param name="userDeclarations">All user declarations.</param>
/// <param name="identifierReferences">All identifier references in user code.</param>
/// <returns></returns>
protected abstract IEnumerable<IParseTreeAnnotation> GetInvalidAnnotations(
IEnumerable<IParseTreeAnnotation> annotations,
IEnumerable<Declaration> userDeclarations,
IEnumerable<IdentifierReference> identifierReferences);

/// <summary>
/// Gets an annotation-specific description for an inspection result.
/// </summary>
/// <param name="pta">The invalid annotation.</param>
/// <returns></returns>
protected abstract string ResultDescription(IParseTreeAnnotation pta);

protected sealed override IEnumerable<IInspectionResult> DoGetInspectionResults(QualifiedModuleName module, DeclarationFinder finder)
{
var annotations = finder.FindAnnotations(module);
var userDeclarations = finder.Members(module).ToList();
var identifierReferences = finder.IdentifierReferences(module).ToList();

var invalidAnnotations = GetInvalidAnnotations(annotations, userDeclarations, identifierReferences);
return invalidAnnotations.Select(InspectionResult).ToList();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Rubberduck.CodeAnalysis.Inspections.Abstract;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Resources.Inspections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// Flags Rubberduck annotations used in a component type that is incompatible with that annotation.
/// </summary>
/// <why>
/// Some annotations can only be used in a specific type of module; others cannot be used in certain types of modules.
/// </why>
/// <example hasResult="true">
/// <module name="MyModule" type="Standard Module">
/// <![CDATA[
/// '@PredeclaredId 'this annotation is illegal in a standard module
/// Option Explicit
/// ]]>
/// </module>
/// </example>
/// <example hasResult="false">
/// <module name="MyModule" type="Class Module">
/// <![CDATA[
/// '@PredeclaredId 'this annotation works fine in a class module
/// Option Explicit
///
/// Public Sub DoSomething()
/// Dim foo As Long
/// End Sub
/// ]]>
/// </module>
/// </example>
internal sealed class AnnotationInIncompatibleComponentTypeInspection : InvalidAnnotationInspectionBase
{
public AnnotationInIncompatibleComponentTypeInspection(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider) { }

protected override IEnumerable<IParseTreeAnnotation> GetInvalidAnnotations(
IEnumerable<IParseTreeAnnotation> annotations,
IEnumerable<Declaration> userDeclarations,
IEnumerable<IdentifierReference> identifierReferences)
{
foreach (var pta in annotations)
{
var annotation = pta.Annotation;
var componentType = pta.QualifiedSelection.QualifiedName.ComponentType;
if (annotation.RequiredComponentType.HasValue && annotation.RequiredComponentType != componentType
|| annotation.IncompatibleComponentTypes.Contains(componentType))
{
yield return pta;
}
}

yield break;
}

protected override string ResultDescription(IParseTreeAnnotation pta)
{
if (pta.Annotation.RequiredComponentType.HasValue)
{
return string.Format(InspectionResults.ResourceManager.GetString("InvalidAnnotationInspection_NotInRequiredComponentType", CultureInfo.CurrentUICulture),
pta.Annotation.Name, // annotation...
pta.QualifiedSelection.QualifiedName.ComponentType, // is used in a...
pta.Annotation.RequiredComponentType); // but is only valid in a...
}
else
{
return string.Format(InspectionResults.ResourceManager.GetString("InvalidAnnotationInspection_IncompatibleComponentType", CultureInfo.CurrentUICulture),
pta.Annotation.Name, // annotation...
pta.QualifiedSelection.QualifiedName.ComponentType); // cannot be used in a...
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using Rubberduck.CodeAnalysis.Inspections.Abstract;
using Rubberduck.CodeAnalysis.Inspections.Abstract;
using Rubberduck.CodeAnalysis.Inspections.Attributes;
using Rubberduck.InternalApi.Extensions;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Parsing.VBA.DeclarationCaching;
using Rubberduck.Resources.Inspections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
Expand Down Expand Up @@ -60,7 +61,7 @@ internal class ApplicationWorksheetFunctionInspection : IdentifierReferenceInspe
{
public ApplicationWorksheetFunctionInspection(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider)
{}
{ }

protected override IEnumerable<Declaration> ObjectionableDeclarations(DeclarationFinder finder)
{
Expand Down Expand Up @@ -91,7 +92,7 @@ protected override IEnumerable<Declaration> ObjectionableDeclarations(Declaratio

protected override string ResultDescription(IdentifierReference reference)
{
return string.Format(InspectionResults.ApplicationWorksheetFunctionInspection, reference.IdentifierName);
return string.Format(InspectionResults.ResourceManager.GetString("ApplicationWorksheetFunctionInspection", CultureInfo.CurrentUICulture), reference.IdentifierName);
}
}
}
Loading

0 comments on commit a84e36f

Please sign in to comment.