Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f18840

Browse files
committed
C#: Extract attributes of referenced assembly
1 parent cdea3af commit 5f18840

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ public void AnalyseTree(SyntaxTree tree)
198198
/// Perform an analysis on an assembly.
199199
/// </summary>
200200
/// <param name="assembly">Assembly to analyse.</param>
201-
private void AnalyseAssembly(PortableExecutableReference assembly)
201+
private void AnalyseReferenceAssembly(PortableExecutableReference assembly)
202202
{
203203
// CIL first - it takes longer.
204204
if (options.CIL)
205205
extractionTasks.Add(() => DoExtractCIL(assembly));
206-
extractionTasks.Add(() => DoAnalyseAssembly(assembly));
206+
extractionTasks.Add(() => DoAnalyseReferenceAssembly(assembly));
207207
}
208208

209209
private static bool FileIsUpToDate(string src, string dest)
@@ -250,7 +250,7 @@ private void DoAnalyseCompilation(string cwd, string[] args)
250250
/// extraction within the snapshot.
251251
/// </summary>
252252
/// <param name="r">The assembly to extract.</param>
253-
private void DoAnalyseAssembly(PortableExecutableReference r)
253+
private void DoAnalyseReferenceAssembly(PortableExecutableReference r)
254254
{
255255
try
256256
{
@@ -294,6 +294,8 @@ private void DoAnalyseAssembly(PortableExecutableReference r)
294294
AnalyseNamespace(cx, module.GlobalNamespace);
295295
}
296296

297+
Entities.Attribute.ExtractAttributes(cx, assembly, Extraction.Entities.Assembly.Create(cx, assembly.GetSymbolLocation()));
298+
297299
cx.PopulateAll();
298300
}
299301
}
@@ -335,7 +337,7 @@ public void AnalyseReferences()
335337
{
336338
foreach (var r in compilation.References.OfType<PortableExecutableReference>())
337339
{
338-
AnalyseAssembly(r);
340+
AnalyseReferenceAssembly(r);
339341
}
340342
}
341343

csharp/ql/test/library-tests/attributes/AttributeElements.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import csharp
33
from Attributable element, Attribute attribute
44
where
55
attribute = element.getAnAttribute() and
6-
(element.(Element).fromSource() or element instanceof Assembly)
6+
(element.(Element).fromSource() or element.(Assembly).getName() = "attributes")
77
select element, attribute, attribute.getType().getQualifiedName()

csharp/ql/test/library-tests/attributes/ExternalAttributeArguments.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
arguments
2+
| Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | 0 | 1 |
3+
| Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | 1 | array creation of type Object[] |
4+
| Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | 2 | typeof(...) |
5+
| Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | 3 | (...) ... |
6+
| Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | 4 | null |
7+
| Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | 5 | array creation of type Object[] |
28
| Class1 | 0 | 3 |
39
| Class1 | 1 | array creation of type Int32[] |
410
| Class1 | 2 | null |
@@ -12,6 +18,7 @@ arguments
1218
| Method1 | 4 | array creation of type Int32[] |
1319
| Method1 | 5 | array creation of type Object[] |
1420
literals
21+
| 1 | Int32 | 1 |
1522
| 3 | Int32 | 3 |
1623
| 42 | Int32 | 42 |
1724
| null | null | null |
@@ -20,9 +27,13 @@ enums
2027
| (...) ... | 43 | access to type Enum1 | 43 |
2128
typeof
2229
| typeof(...) | access to type Class1 |
30+
| typeof(...) | access to type CustomAttribute |
2331
array
2432
| array creation of type Int32[] | 3 | 0 | 1 |
2533
| array creation of type Int32[] | 3 | 1 | 2 |
2634
| array creation of type Int32[] | 3 | 2 | 3 |
2735
| array creation of type Object[] | 2 | 0 | 1 |
2836
| array creation of type Object[] | 2 | 1 | typeof(...) |
37+
| array creation of type Object[] | 3 | 0 | 1 |
38+
| array creation of type Object[] | 3 | 1 | 2 |
39+
| array creation of type Object[] | 3 | 2 | null |

0 commit comments

Comments
 (0)