Skip to content

Commit

Permalink
formatting and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Seppli11 committed Nov 26, 2024
1 parent e5792f3 commit f280073
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void computeDependencies(Assignment assignment, Set<SymbolV2> trackedVar
if (e instanceof Name name) {
SymbolV2 symbol = name.symbolV2();
if (symbol != null && trackedVars.contains(symbol)) {
assignment.addVariableDependencies(symbol);
assignment.addVariableDependency(symbol);
propagationsByLhs.get(symbol).forEach(propagation -> propagation.addDependent(assignment));
}
} else if (e instanceof HasTypeDependencies hasTypeDependencies) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SymbolV2 lhsSymbol() {
return lhsSymbol;
}

public void addVariableDependencies(SymbolV2 dependency) {
public void addVariableDependency(SymbolV2 dependency) {
variableDependencies.add(dependency);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
import org.sonar.python.types.v2.TypeUtils;

public class TrivialTypePropagationVisitor extends BaseTreeVisitor {
private TypeCheckBuilder isBooleanTypeCheck;
private TypeCheckBuilder isIntTypeCheck;
private TypeCheckBuilder isFloatTypeCheck;
private TypeCheckBuilder isComplexTypeCheck;
private final TypeCheckBuilder isBooleanTypeCheck;
private final TypeCheckBuilder isIntTypeCheck;
private final TypeCheckBuilder isFloatTypeCheck;
private final TypeCheckBuilder isComplexTypeCheck;

private PythonType intType;
private PythonType boolType;
private final PythonType intType;
private final PythonType boolType;

public TrivialTypePropagationVisitor(TypeTable typeTable) {
this.isBooleanTypeCheck = new TypeCheckBuilder(typeTable).isBuiltinWithName(BuiltinTypes.BOOL);
Expand Down Expand Up @@ -76,20 +76,20 @@ private PythonType getTypeWhenUnaryPlusMinus(UnaryExpression unaryExpr) {
private PythonType mapUnaryPlusMinusType(PythonType type) {
if (isNumber(type)) {
return type;
} else if(isBooleanTypeCheck.check(type) == TriBool.TRUE) {
} else if (isBooleanTypeCheck.check(type) == TriBool.TRUE) {
return toObjectType(intType);
}
return PythonType.UNKNOWN;
}

private boolean isNumber(PythonType type) {
private boolean isNumber(PythonType type) {
return isIntTypeCheck.check(type) == TriBool.TRUE
|| isFloatTypeCheck.check(type) == TriBool.TRUE
|| isComplexTypeCheck.check(type) == TriBool.TRUE;
}

private static PythonType toObjectType(PythonType type) {
if(type instanceof ObjectType || type == PythonType.UNKNOWN) {
if (type instanceof ObjectType || type == PythonType.UNKNOWN) {
return type;
}
return new ObjectType(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static PythonType ensureWrappedObjectType(PythonType pythonType) {
}

public static PythonType map(PythonType type, UnaryOperator<PythonType> mapper) {
if(type instanceof UnionType unionType) {
if (type instanceof UnionType unionType) {
return unionType.candidates().stream().map(mapper).reduce(UnionType::or).orElse(PythonType.UNKNOWN);
} else {
return mapper.apply(type);
Expand Down

0 comments on commit f280073

Please sign in to comment.