Skip to content

Commit 20d037d

Browse files
joke1196Seppli11
authored andcommitted
Clean up and refactor Propagation and Assignment
1 parent 6cebff7 commit 20d037d

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

python-frontend/src/main/java/org/sonar/python/semantic/v2/types/Assignment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public Assignment(SymbolV2 lhsSymbol, Name lhsName, Expression rhs, Map<SymbolV2
3737
this.propagationsByLhs = propagationsByLhs;
3838
}
3939

40-
void computeDependencies(Expression expression, Set<SymbolV2> trackedVars) {
40+
void computeDependencies(Set<SymbolV2> trackedVars) {
4141
Deque<Expression> workList = new ArrayDeque<>();
42-
workList.push(expression);
42+
workList.push(rhs);
4343
while (!workList.isEmpty()) {
4444
Expression e = workList.pop();
4545
if (e instanceof Name name) {

python-frontend/src/main/java/org/sonar/python/semantic/v2/types/ProgramStateTypeInferenceVisitor.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ public void visitQualifiedExpression(QualifiedExpression qualifiedExpression) {
6565
}
6666
}
6767

68-
private static PythonType or(PythonType t1, PythonType t2) {
69-
return UnionType.or(t1, t2);
70-
}
71-
7268
private static PythonType union(Stream<PythonType> types) {
73-
return types.reduce(ProgramStateTypeInferenceVisitor::or).orElse(PythonType.UNKNOWN);
69+
return types.reduce(UnionType::or).orElse(PythonType.UNKNOWN);
7470
}
7571
}

python-frontend/src/main/java/org/sonar/python/semantic/v2/types/Propagation.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,8 @@ Set<Propagation> dependents() {
111111
static PythonType currentType(Name lhsName) {
112112
return Optional.ofNullable(lhsName.symbolV2())
113113
.stream()
114-
.map(SymbolV2::usages)
115-
.flatMap(List::stream)
116-
.filter(u -> !SymbolV2Utils.isDeclaration(u))
117-
.map(UsageV2::tree)
118-
.filter(Expression.class::isInstance)
119-
.map(Expression.class::cast)
114+
.flatMap(Propagation::getSymbolNonDeclarationUsageTrees)
115+
.flatMap(TreeUtils.toStreamInstanceOfMapper(Expression.class))
120116
.findFirst()
121117
.map(Expression::typeV2)
122118
.orElse(null);

python-frontend/src/main/java/org/sonar/python/semantic/v2/types/PropagationVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public Map<SymbolV2, Set<PythonType>> processPropagations(Set<SymbolV2> trackedV
209209
props.stream()
210210
.filter(Assignment.class::isInstance)
211211
.map(Assignment.class::cast)
212-
.forEach(a -> a.computeDependencies(a.rhs(), trackedVars));
212+
.forEach(a -> a.computeDependencies(trackedVars));
213213
propagations.addAll(props);
214214
}
215215
});

0 commit comments

Comments
 (0)