forked from TNG/ArchUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
analyze local variable instantiations
So far local variable instantiations were not analyzed at all, leaving gaps in the evaluation of dependency rules. If a local variable of a certain type was instantiated in a method, but no other use of that type was present (e.g. a method call on the type, or a field access), the dependency from the method to that type was undetected. Here, if enabled by a new configuration property (to preserve backward compatibility and performance), local variable instantiations add class dependencies from the surrounding method to the type of the variable and, if that type has generic type parameters, also from the method to any concrete generic type. Issue: TNG#768
- Loading branch information
Showing
5 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 41 additions & 4 deletions
45
...mporter/testexamples/referencedclassobjects/ReferencingClassObjectsFromLocalVariable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,56 @@ | ||
package com.tngtech.archunit.core.importer.testexamples.referencedclassobjects; | ||
|
||
import java.io.FilterInputStream; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
@SuppressWarnings("unused") | ||
public class ReferencingClassObjectsFromLocalVariable { | ||
public class ReferencingClassObjectsFromLocalVariable<T extends Number> { | ||
|
||
static { | ||
FilterInputStream streamStatic = null; | ||
List<Double> listStatic = new ArrayList<>(); | ||
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") List<Double> listStatic = new ArrayList<>(); | ||
//noinspection ResultOfMethodCallIgnored | ||
listStatic.size(); // if listStatic is not used it is optimized away. Surprisingly this is not the case for streamStatic above | ||
} | ||
|
||
void reference() { FilterInputStream stream = null; } | ||
void reference() { | ||
FilterInputStream stream = null; | ||
InputStream stream2 = null; | ||
System.out.println(stream); | ||
System.out.println(stream2); | ||
// after statement and comment | ||
FilterInputStream stream3 = null; | ||
InputStream stream4 = null; | ||
System.out.println(stream3); | ||
System.out.println(stream4); | ||
{ | ||
// in block | ||
FilterInputStream stream5 = null; | ||
InputStream stream6 = null; | ||
System.out.println(stream5); | ||
System.out.println(stream6); | ||
} | ||
} | ||
|
||
void referenceByGeneric() { | ||
List<FilterInputStream> list = null; | ||
List<InputStream> list2 = null; | ||
// multiple generic parameters | ||
Map<FilterInputStream, InputStream> map = null; | ||
// nested generic parameters | ||
Map<Set<FilterInputStream>, InputStream> map2 = null; | ||
System.out.println(list); | ||
System.out.println(list2); | ||
System.out.println(map); | ||
System.out.println(map2); | ||
} | ||
|
||
void referenceByGeneric() { List<FilterInputStream> list = null; } | ||
void referenceToOwnGenericType() { | ||
T myType = null; | ||
System.out.println(myType); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters