Skip to content

Commit efcf142

Browse files
committed
chore: Hardware failure.
1 parent 1fc4ead commit efcf142

3 files changed

Lines changed: 83 additions & 6 deletions

File tree

assis-core/src/main/java/io/github/masmangan/assis/internal/CollectDependenciesVisitor.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,18 @@ public void visit(ClassExpr n, DependencyContext ctx) {
132132
// no samples!
133133
@Override
134134
public void visit(MethodCallExpr n, DependencyContext ctx) {
135-
n.getScope().ifPresent(scope -> {
136-
if (scope instanceof NameExpr ne) {
137-
recordScope(ne.getNameAsString(), n, ctx);
138-
}
139-
});
140-
super.visit(n, ctx);
135+
n.getScope().ifPresent(scope -> {
136+
if (scope instanceof NameExpr ne) {
137+
recordScope(ne, n, ctx); // pass the node
138+
}
139+
});
140+
super.visit(n, ctx);
141+
}
142+
143+
private void recordScope(NameExpr scopeExpr, Node site, DependencyContext ctx) {
144+
if (ownerStack.isEmpty()) return;
145+
ctx.resolveScope(scopeExpr, site)
146+
.ifPresent(target -> collect(owner(), target, ctx));
141147
}
142148

143149
private void enter(TypeDeclaration<?> td) {

assis-core/src/main/java/io/github/masmangan/assis/internal/DeclaredIndex.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.github.javaparser.ast.body.EnumDeclaration;
3030
import com.github.javaparser.ast.body.Parameter;
3131
import com.github.javaparser.ast.body.TypeDeclaration;
32+
import com.github.javaparser.ast.expr.NameExpr;
3233
import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
3334
import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAccessModifiers;
3435
import com.github.javaparser.ast.type.ArrayType;
@@ -660,4 +661,64 @@ public Optional<TypeRef> resolveScopeName(String simpleName, Node usageSite) {
660661
return Optional.of(new UnresolvedTypeRef(simpleName));
661662
}
662663

664+
public Optional<TypeRef> resolveScope(NameExpr scopeExpr, Node usageSite) {
665+
try {
666+
var valueDecl = scopeExpr.resolve(); // ResolvedValueDeclaration
667+
var valueType = valueDecl.getType(); // ResolvedType
668+
return resolveResolvedTypeToTypeRef(valueType, usageSite);
669+
} catch (Exception e) {
670+
// fallback(s) below
671+
}
672+
673+
// Fallback 1: sometimes NameExpr is actually a type name used as qualifier (static call)
674+
String name = scopeExpr.getNameAsString();
675+
TypeDeclaration<?> indexed = getByFqn(name);
676+
if (indexed != null) return Optional.of(new DeclaredTypeRef(indexed));
677+
678+
// Fallback 2: return unresolved *type* ref? I'd avoid emitting a dependency to a bare variable name:
679+
return Optional.empty(); // <- prevents "A ..> b"
680+
}
681+
682+
private Optional<TypeRef> resolveResolvedTypeToTypeRef(
683+
ResolvedType rt,
684+
Node usageSite
685+
) {
686+
// 1) Primitives → no dependency
687+
if (rt.isPrimitive()) {
688+
return Optional.empty();
689+
}
690+
691+
// 2) Void → no dependency
692+
if (rt.isVoid()) {
693+
return Optional.empty();
694+
}
695+
696+
// 3) Reference types (classes, interfaces, enums)
697+
if (rt.isReferenceType()) {
698+
var rrt = rt.asReferenceType();
699+
var qname = rrt.getQualifiedName(); // dot-qualified, not JVM $
700+
701+
// a) Declared in our parsed sources
702+
TypeDeclaration<?> td = getByFqn(qname);
703+
if (td != null) {
704+
return Optional.of(new DeclaredTypeRef(td));
705+
}
706+
707+
// b) Known but external (JDK, libs)
708+
return Optional.of(new ExternalTypeRef(qname));
709+
}
710+
711+
// 4) Arrays → dependency on component type
712+
if (rt.isArray()) {
713+
return resolveResolvedTypeToTypeRef(
714+
rt.asArrayType().getComponentType(),
715+
usageSite
716+
);
717+
}
718+
719+
// 5) Type variables, wildcards, etc.
720+
// Usually not diagram-worthy on their own
721+
return Optional.empty();
722+
}
723+
663724
}

assis-core/src/main/java/io/github/masmangan/assis/internal/DependencyContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import com.github.javaparser.ast.Node;
1111
import com.github.javaparser.ast.body.TypeDeclaration;
12+
import com.github.javaparser.ast.expr.Expression;
13+
import com.github.javaparser.ast.expr.NameExpr;
1214
import com.github.javaparser.ast.type.Type;
1315

1416
import io.github.masmangan.assis.io.PlantUMLWriter;
@@ -106,4 +108,12 @@ public void addCherryPick(TypeDeclaration<?> from, TypeRef to) {
106108
er.registerDependency(fromFqn, toFqn);
107109
}
108110

111+
public Optional<TypeRef> resolveScope(NameExpr scopeExpr, Node usageSite) {
112+
return idx.resolveScope(scopeExpr, usageSite);
113+
}
114+
109115
}
116+
117+
118+
119+

0 commit comments

Comments
 (0)