Review fixes after automatic code analysis

This commit is contained in:
Mikhail Glukhikh
2015-04-20 19:01:05 +03:00
parent 27625b04e1
commit e64dab0ae9
23 changed files with 62 additions and 56 deletions
@@ -534,6 +534,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
JetExpression loopRange = forExpression.getLoopRange();
assert loopRange != null;
JetType loopRangeType = bindingContext.getType(loopRange);
assert loopRangeType != null;
Type asmLoopRangeType = asmType(loopRangeType);
@@ -3531,7 +3532,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@Override
public StackValue visitArrayAccessExpression(@NotNull JetArrayAccessExpression expression, StackValue receiver) {
JetExpression array = expression.getArrayExpression();
JetType type = bindingContext.getType(array);
JetType type = array != null ? bindingContext.getType(array) : null;
Type arrayType = expressionType(array);
List<JetExpression> indices = expression.getIndexExpressions();
FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(REFERENCE_TARGET, expression);
@@ -1266,7 +1266,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
result.addField((JetDelegatorByExpressionSpecifier) specifier, propertyDescriptor);
}
else {
JetType expressionType = bindingContext.getType(expression);
JetType expressionType = expression != null ? bindingContext.getType(expression) : null;
Type asmType =
expressionType != null ? typeMapper.mapType(expressionType) : typeMapper.mapType(getSuperClass(specifier));
result.addField((JetDelegatorByExpressionSpecifier) specifier, asmType, "$delegate_" + n);
@@ -283,6 +283,7 @@ public class PropertyCodegen {
}
private void generatePropertyDelegateAccess(JetProperty p, PropertyDescriptor propertyDescriptor) {
assert p.getDelegateExpression() != null: "Property must have a delegate expression here";
JetType delegateType = bindingContext.getType(p.getDelegateExpression());
if (delegateType == null) {
// If delegate expression is unresolved reference
@@ -515,6 +515,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
int fieldNumber = mappings.size();
assert expression.getSubjectExpression() != null : "subject expression should be not null in a valid when by enums";
JetType type = bindingContext.getType(expression.getSubjectExpression());
assert type != null : "should not be null in a valid when by enums";
ClassDescriptor classDescriptor = (ClassDescriptor) type.getConstructor().getDeclarationDescriptor();
@@ -130,6 +130,7 @@ abstract public class SwitchCodegen {
}
protected void generateNullCheckIfNeeded() {
assert expression.getSubjectExpression() != null : "subject expression can't be null";
JetType subjectJetType = bindingContext.getType(expression.getSubjectExpression());
assert subjectJetType != null : "subject type can't be null (i.e. void)";
@@ -228,7 +228,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
when (expression.getOperationToken()) {
JetTokens.ELVIS -> {
val baseExpression = expression.getLeft()
val baseExpressionType = c.trace.getType(baseExpression) ?: return
val baseExpressionType = baseExpression?.let{ c.trace.getType(it) } ?: return
doIfNotNull(
DataFlowValueFactory.createDataFlowValue(baseExpression, baseExpressionType, c),
c
@@ -111,8 +111,7 @@ public final class WhenChecker {
for (JetWhenEntry entry : expression.getEntries()) {
for (JetWhenCondition condition : entry.getConditions()) {
if (condition instanceof JetWhenConditionWithExpression) {
JetType type = trace.getBindingContext().getType(((JetWhenConditionWithExpression) condition).getExpression()
);
JetType type = trace.getBindingContext().getType(((JetWhenConditionWithExpression) condition).getExpression());
if (type != null && KotlinBuiltIns.isNothingOrNullableNothing(type)) {
return true;
}
@@ -76,6 +76,7 @@ public interface BindingContext {
}
@Nullable
@Override
public JetType getType(@NotNull JetExpression expression) {
return null;
}
@@ -65,8 +65,8 @@ public class CompositeBindingContext private (
) : Diagnostics {
override fun iterator(): Iterator<Diagnostic> {
val emptyStream = listOf<Diagnostic>().stream()
return delegates.fold(emptyStream, { r, t -> r + t.stream() }).iterator()
val emptyStream = listOf<Diagnostic>().sequence()
return delegates.fold(emptyStream, { r, t -> r + t.sequence() }).iterator()
}
override val modificationTracker = object : ModificationTracker {
@@ -229,7 +229,7 @@ public class CallCompleter(
val deparenthesized = ArgumentTypeResolver.getLastElementDeparenthesized(expression, context)
if (deparenthesized == null) return
val recordedType = context.trace.getType(expression)
val recordedType = expression?.let { context.trace.getType(it) }
var updatedType: JetType? = recordedType
val results = completeCallForArgument(deparenthesized, context)
@@ -297,7 +297,7 @@ public class CallCompleter(
val expressions = ArrayList<JetExpression>()
var expression: JetExpression? = argumentExpression
while (expression != null) {
expressions.add(expression!!)
expressions.add(expression)
expression = deparenthesizeOrGetSelector(expression)
}
expressions.forEach { expression ->
@@ -94,7 +94,7 @@ public fun Call.getValueArgumentForExpression(expression: JetExpression): ValueA
else -> null
}
}
fun JetElement.isParenthesizedExpression() = stream(this) { it.deparenthesizeStructurally() }.any { it == expression }
fun JetElement.isParenthesizedExpression() = sequence(this) { it.deparenthesizeStructurally() }.any { it == expression }
return getValueArguments().firstOrNull { it?.getArgumentExpression()?.isParenthesizedExpression() ?: false }
}
@@ -475,7 +475,7 @@ private fun hasLongSuffix(text: String) = text.endsWith('l') || text.endsWith('L
public fun parseLong(text: String): Long? {
try {
fun substringLongSuffix(s: String) = if (hasLongSuffix(text)) s.substring(0, s.length - 1) else s
fun substringLongSuffix(s: String) = if (hasLongSuffix(text)) s.substring(0, s.length() - 1) else s
fun parseLong(text: String, radix: Int) = java.lang.Long.parseLong(substringLongSuffix(text), radix)
return when {