File tree Expand file tree Collapse file tree
src/main/java/it/aboutbits/archunit/toolbox/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66import com .tngtech .archunit .core .domain .JavaMethod ;
77import com .tngtech .archunit .core .domain .JavaParameterizedType ;
88import com .tngtech .archunit .core .domain .JavaStaticInitializer ;
9+ import com .tngtech .archunit .core .domain .properties .HasSourceCodeLocation ;
910import org .jspecify .annotations .NullMarked ;
1011
1112import java .util .List ;
13+ import java .util .NoSuchElementException ;
1214import java .util .Set ;
1315import java .util .function .Function ;
1416import java .util .stream .Stream ;
@@ -18,6 +20,23 @@ public final class LineNumberUtil {
1820 private LineNumberUtil () {
1921 }
2022
23+ public static int getLineNumber (HasSourceCodeLocation element ) {
24+ return element .getSourceCodeLocation ().getLineNumber ();
25+ }
26+
27+ // JavaClass overload with constructor fallback: class-level SLOC is 0 for nested/anonymous classes
28+ public static int getLineNumber (JavaClass javaClass ) {
29+ var lineNumber = javaClass .getSourceCodeLocation ().getLineNumber ();
30+ if (lineNumber != 0 ) {
31+ return lineNumber ;
32+ }
33+ try {
34+ return javaClass .getConstructors ().iterator ().next ().getSourceCodeLocation ().getLineNumber ();
35+ } catch (NoSuchElementException _) {
36+ return 0 ;
37+ }
38+ }
39+
2140 public static List <LineNumberType > getDependencyUsageLineNumberTypes (
2241 JavaClass originClass ,
2342 JavaClass targetClass
You can’t perform that action at this time.
0 commit comments