提交 d4d9ac7b 编写于 作者: A Andrey Breslav

Null checks

上级 48fdfc54
......@@ -34,7 +34,7 @@ public class JetControlFlowProcessor {
public void generateSubroutineControlFlow(@NotNull JetElement subroutineElement, @NotNull List<? extends JetElement> body, boolean preferBlocks) {
if (subroutineElement instanceof JetNamedDeclaration) {
JetNamedDeclaration namedDeclaration = (JetNamedDeclaration) subroutineElement;
enterLabeledElement(namedDeclaration.getName(), namedDeclaration);
enterLabeledElement(JetPsiUtil.safeName(namedDeclaration.getName()), namedDeclaration);
}
boolean functionLiteral = subroutineElement instanceof JetFunctionLiteralExpression;
builder.enterSubroutine(subroutineElement, functionLiteral);
......@@ -107,7 +107,10 @@ public class JetControlFlowProcessor {
@Override
public void visitParenthesizedExpression(JetParenthesizedExpression expression) {
value(expression.getExpression(), false);
JetExpression innerExpression = expression.getExpression();
if (innerExpression != null) {
value(innerExpression, false);
}
}
@Override
......@@ -129,7 +132,9 @@ public class JetControlFlowProcessor {
public void visitLabelQualifiedExpression(JetLabelQualifiedExpression expression) {
String labelName = expression.getLabelName();
JetExpression labeledExpression = expression.getLabeledExpression();
visitLabeledExpression(labelName, labeledExpression);
if (labelName != null && labeledExpression != null) {
visitLabeledExpression(labelName, labeledExpression);
}
}
private void visitLabeledExpression(@NotNull String labelName, @NotNull JetExpression labeledExpression) {
......@@ -143,23 +148,30 @@ public class JetControlFlowProcessor {
@Override
public void visitBinaryExpression(JetBinaryExpression expression) {
IElementType operationType = expression.getOperationReference().getReferencedNameElementType();
JetExpression right = expression.getRight();
if (operationType == JetTokens.ANDAND) {
value(expression.getLeft(), false);
Label resultLabel = builder.createUnboundLabel();
builder.jumpOnFalse(resultLabel);
value(expression.getRight(), false);
if (right != null) {
value(right, false);
}
builder.bindLabel(resultLabel);
}
else if (operationType == JetTokens.OROR) {
value(expression.getLeft(), false);
Label resultLabel = builder.createUnboundLabel();
builder.jumpOnTrue(resultLabel);
value(expression.getRight(), false);
if (right != null) {
value(right, false);
}
builder.bindLabel(resultLabel);
}
else {
value(expression.getLeft(), false);
value(expression.getRight(), false);
if (right != null) {
value(right, false);
}
builder.readNode(expression);
}
}
......@@ -168,7 +180,9 @@ public class JetControlFlowProcessor {
public void visitUnaryExpression(JetUnaryExpression expression) {
IElementType operationType = expression.getOperationSign().getReferencedNameElementType();
if (JetTokens.LABELS.contains(operationType)) {
visitLabeledExpression(expression.getOperationSign().getReferencedName().substring(1), expression.getBaseExpression());
String referencedName = expression.getOperationSign().getReferencedName();
referencedName = referencedName == null ? " <?>" : referencedName;
visitLabeledExpression(referencedName.substring(1), expression.getBaseExpression());
}
else {
visitElement(expression);
......
......@@ -15,4 +15,9 @@ public class JetPsiUtil {
}
return result;
}
@NotNull
public static String safeName(String name) {
return name == null ? "<no name provided>" : name;
}
}
......@@ -30,7 +30,7 @@ public class ClassDescriptorResolver {
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
scope.getContainingDeclaration(),
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
safeName(classElement.getName()));
JetPsiUtil.safeName(classElement.getName()));
trace.recordDeclarationResolution(classElement, classDescriptor);
......@@ -81,7 +81,7 @@ public class ClassDescriptorResolver {
descriptor,
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
!open,
safeName(classElement.getName()),
JetPsiUtil.safeName(classElement.getName()),
typeParameters,
supertypes);
descriptor.setTypeConstructor(
......@@ -157,7 +157,7 @@ public class ClassDescriptorResolver {
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(
containingDescriptor,
AttributeResolver.INSTANCE.resolveAttributes(function.getModifierList()),
safeName(function.getName())
JetPsiUtil.safeName(function.getName())
);
WritableScope innerScope = semanticServices.createWritableScope(scope, functionDescriptor);
innerScope.addLabeledDeclaration(functionDescriptor);
......@@ -216,7 +216,7 @@ public class ClassDescriptorResolver {
functionDescriptor,
i,
AttributeResolver.INSTANCE.resolveAttributes(valueParameter.getModifierList()),
safeName(valueParameter.getName()),
JetPsiUtil.safeName(valueParameter.getName()),
valueParameter.isMutable() ? type : null,
type,
valueParameter.getDefaultValue() != null,
......@@ -250,7 +250,7 @@ public class ClassDescriptorResolver {
containingDescriptor,
AttributeResolver.INSTANCE.resolveAttributes(typeParameter.getModifierList()),
typeParameter.getVariance(),
safeName(typeParameter.getName()),
JetPsiUtil.safeName(typeParameter.getName()),
Collections.singleton(bound),
bound
);
......@@ -299,7 +299,7 @@ public class ClassDescriptorResolver {
PropertyDescriptor propertyDescriptor = new PropertyDescriptorImpl(
containingDeclaration,
AttributeResolver.INSTANCE.resolveAttributes(parameter.getModifierList()),
safeName(parameter.getName()),
JetPsiUtil.safeName(parameter.getName()),
parameter.isMutable() ? null : type,
type);
trace.recordDeclarationResolution(parameter, propertyDescriptor);
......@@ -327,7 +327,7 @@ public class ClassDescriptorResolver {
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
containingDeclaration,
AttributeResolver.INSTANCE.resolveAttributes(property.getModifierList()),
safeName(property.getName()),
JetPsiUtil.safeName(property.getName()),
property.isVar() ? type : null,
type);
trace.recordDeclarationResolution(property, propertyDescriptor);
......@@ -397,8 +397,4 @@ public class ClassDescriptorResolver {
return propertyDescriptor;
}
@NotNull
private static String safeName(String name) {
return name == null ? "<no name provided>" : name;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册