little renames

This commit is contained in:
svtk
2011-08-16 19:23:26 +04:00
parent 9fa146f4d5
commit fabf7aab5f
5 changed files with 37 additions and 53 deletions
@@ -46,6 +46,6 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
@Override @Override
public String toString() { public String toString() {
return DescriptorRenderer.TEXT_FOR_DEBUG.render(this) + "[" + getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + "]"; return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this)) + "]";
} }
} }
@@ -257,6 +257,6 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
@Override @Override
public String toString() { public String toString() {
return DescriptorRenderer.TEXT_FOR_DEBUG.render(this) + "[" + getClass().getCanonicalName() + "@" + System.identityHashCode(this) + "]"; return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getCanonicalName() + "@" + System.identityHashCode(this) + "]";
} }
} }
@@ -85,7 +85,7 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
@Override @Override
public String toString() { public String toString() {
return DescriptorRenderer.TEXT_FOR_DEBUG.render(this); return DescriptorRenderer.TEXT.render(this);
} }
@NotNull @NotNull
@@ -1024,10 +1024,9 @@ public class JetTypeInferrer {
return context.services.checkEnrichedType(result, expression, context); return context.services.checkEnrichedType(result, expression, context);
} }
else { else {
//TODO JetType[] result = new JetType[1];
LookupResult result = furtherNameLookup(expression, referencedName, context); if (furtherNameLookup(expression, referencedName, result, context)) {
if (result.found) { return context.services.checkEnrichedType(result[0], expression, context);
return context.services.checkEnrichedType(result.type, expression, context);
} }
} }
@@ -1042,23 +1041,13 @@ public class JetTypeInferrer {
return false; return false;
} }
protected class LookupResult { protected boolean furtherNameLookup(@NotNull JetSimpleNameExpression expression, @NotNull String referencedName, @NotNull JetType[] result, TypeInferenceContext context) {
private final JetType type;
private final boolean found;
LookupResult(JetType type, boolean found) {
this.type = type;
this.found = found;
}
}
protected LookupResult furtherNameLookup(@NotNull JetSimpleNameExpression expression, @NotNull String referencedName, TypeInferenceContext context) {
NamespaceType namespaceType = lookupNamespaceType(expression, referencedName, context); NamespaceType namespaceType = lookupNamespaceType(expression, referencedName, context);
if (namespaceType != null) { if (namespaceType != null) {
context.trace.getErrorHandler().genericError(expression.getNode(), "Expression expected, but a namespace name found"); context.trace.getErrorHandler().genericError(expression.getNode(), "Expression expected, but a namespace name found");
return new LookupResult(null, true); return true;
} }
return new LookupResult(null, false); return false;
} }
@Nullable @Nullable
@@ -1098,12 +1087,11 @@ public class JetTypeInferrer {
} }
@Override @Override
public JetType visitFunctionLiteralExpression(JetFunctionLiteralExpression expression, TypeInferenceContext contextWithExpectedType) { public JetType visitFunctionLiteralExpression(JetFunctionLiteralExpression expression, TypeInferenceContext context) {
TypeInferenceContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE);
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
if (context.preferBlock && !functionLiteral.hasParameterSpecification()) { if (context.preferBlock && !functionLiteral.hasParameterSpecification()) {
context.trace.recordBlock(expression); context.trace.recordBlock(expression);
return context.services.checkType(getBlockReturnedType(context.scope, functionLiteral.getBodyExpression(), contextWithExpectedType), expression, contextWithExpectedType); return context.services.checkType(getBlockReturnedType(context.scope, functionLiteral.getBodyExpression(), context), expression, context);
} }
JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef(); JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef();
@@ -1149,8 +1137,8 @@ public class JetTypeInferrer {
context.services.checkFunctionReturnType(functionInnerScope, expression, returnType, context.dataFlowInfo); context.services.checkFunctionReturnType(functionInnerScope, expression, returnType, context.dataFlowInfo);
} }
else { else {
if (contextWithExpectedType.expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isFunctionType(contextWithExpectedType.expectedType)) { if (context.expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isFunctionType(context.expectedType)) {
returnType = JetStandardClasses.getReturnType(contextWithExpectedType.expectedType); returnType = JetStandardClasses.getReturnType(context.expectedType);
} }
returnType = getBlockReturnedType(functionInnerScope, functionLiteral.getBodyExpression(), context.replaceExpectedType(returnType)); returnType = getBlockReturnedType(functionInnerScope, functionLiteral.getBodyExpression(), context.replaceExpectedType(returnType));
} }
@@ -1158,7 +1146,7 @@ public class JetTypeInferrer {
functionDescriptor.setReturnType(safeReturnType); functionDescriptor.setReturnType(safeReturnType);
return context.services.checkType(JetStandardClasses.getFunctionType(Collections.<AnnotationDescriptor>emptyList(), effectiveReceiverType, parameterTypes, safeReturnType), expression, contextWithExpectedType); return context.services.checkType(JetStandardClasses.getFunctionType(Collections.<AnnotationDescriptor>emptyList(), effectiveReceiverType, parameterTypes, safeReturnType), expression, context);
} }
@Override @Override
@@ -1248,10 +1236,9 @@ public class JetTypeInferrer {
} }
@Override @Override
public JetType visitBinaryWithTypeRHSExpression(JetBinaryExpressionWithTypeRHS expression, TypeInferenceContext contextWithExpectedType) { public JetType visitBinaryWithTypeRHSExpression(JetBinaryExpressionWithTypeRHS expression, TypeInferenceContext context) {
TypeInferenceContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE);
IElementType operationType = expression.getOperationSign().getReferencedNameElementType(); IElementType operationType = expression.getOperationSign().getReferencedNameElementType();
JetType actualType = getType(context.scope, expression.getLeft(), false, context); JetType actualType = getType(context.scope, expression.getLeft(), false, context.replaceExpectedType(NO_EXPECTED_TYPE));
JetTypeReference right = expression.getRight(); JetTypeReference right = expression.getRight();
JetType result = null; JetType result = null;
if (right != null) { if (right != null) {
@@ -1274,7 +1261,7 @@ public class JetTypeInferrer {
context.trace.getErrorHandler().genericError(expression.getOperationSign().getNode(), "Unsupported binary operation"); context.trace.getErrorHandler().genericError(expression.getOperationSign().getNode(), "Unsupported binary operation");
} }
} }
return context.services.checkType(result, expression, contextWithExpectedType); return context.services.checkType(result, expression, context);
} }
private void checkForCastImpossibility(JetBinaryExpressionWithTypeRHS expression, JetType actualType, JetType targetType, TypeInferenceContext context) { private void checkForCastImpossibility(JetBinaryExpressionWithTypeRHS expression, JetType actualType, JetType targetType, TypeInferenceContext context) {
@@ -1625,8 +1612,7 @@ public class JetTypeInferrer {
} }
@Override @Override
public JetType visitTryExpression(JetTryExpression expression, TypeInferenceContext contextWithExpectedType) { public JetType visitTryExpression(JetTryExpression expression, TypeInferenceContext context) {
TypeInferenceContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE);
JetExpression tryBlock = expression.getTryBlock(); JetExpression tryBlock = expression.getTryBlock();
List<JetCatchClause> catchClauses = expression.getCatchClauses(); List<JetCatchClause> catchClauses = expression.getCatchClauses();
JetFinallySection finallyBlock = expression.getFinallyBlock(); JetFinallySection finallyBlock = expression.getFinallyBlock();
@@ -1639,7 +1625,7 @@ public class JetTypeInferrer {
if (catchBody != null) { if (catchBody != null) {
WritableScope catchScope = newWritableScopeImpl(context.scope, context.trace).setDebugName("Catch scope"); WritableScope catchScope = newWritableScopeImpl(context.scope, context.trace).setDebugName("Catch scope");
catchScope.addVariableDescriptor(variableDescriptor); catchScope.addVariableDescriptor(variableDescriptor);
JetType type = getType(catchScope, catchBody, true, contextWithExpectedType); JetType type = getType(catchScope, catchBody, true, context);
if (type != null) { if (type != null) {
types.add(type); types.add(type);
} }
@@ -1648,12 +1634,12 @@ public class JetTypeInferrer {
} }
if (finallyBlock != null) { if (finallyBlock != null) {
types.clear(); // Do not need the list for the check, but need the code above to typecheck catch bodies types.clear(); // Do not need the list for the check, but need the code above to typecheck catch bodies
JetType type = getType(context.scope, finallyBlock.getFinalExpression(), true, contextWithExpectedType); JetType type = getType(context.scope, finallyBlock.getFinalExpression(), true, context);
if (type != null) { if (type != null) {
types.add(type); types.add(type);
} }
} }
JetType type = getType(context.scope, tryBlock, true, contextWithExpectedType); JetType type = getType(context.scope, tryBlock, true, context);
if (type != null) { if (type != null) {
types.add(type); types.add(type);
} }
@@ -2133,6 +2119,12 @@ public class JetTypeInferrer {
ErrorHandlerWithRegions errorHandler = context.trace.getErrorHandler(); ErrorHandlerWithRegions errorHandler = context.trace.getErrorHandler();
errorHandler.openRegion(); errorHandler.openRegion();
JetType selectorReturnType = getSelectorReturnType(receiverType, selectorExpression, context); JetType selectorReturnType = getSelectorReturnType(receiverType, selectorExpression, context);
// if (expression instanceof JetSafeQualifiedExpression) {
// if (!selectorReturnType.isNullable()) {
// TypeUtils.makeNullable(selectorReturnType);
// }
// }
if (selectorReturnType != null) { if (selectorReturnType != null) {
errorHandler.closeAndCommitCurrentRegion(); errorHandler.closeAndCommitCurrentRegion();
@@ -2183,7 +2175,7 @@ public class JetTypeInferrer {
context.services.checkNullSafety(receiverType, expression.getOperationTokenNode(), getCalleeFunctionDescriptor(selectorExpression, context)); context.services.checkNullSafety(receiverType, expression.getOperationTokenNode(), getCalleeFunctionDescriptor(selectorExpression, context));
} }
} }
return context.services.checkType(result, expression, context); return context.services.checkType(result, expression, contextWithExpectedType);
} }
@@ -2233,8 +2225,7 @@ public class JetTypeInferrer {
return result[0]; return result[0];
} }
private JetType getCallExpressionType(@Nullable JetType receiverType, @NotNull JetCallExpression callExpression, TypeInferenceContext contextWithExpectedType) { private JetType getCallExpressionType(@Nullable JetType receiverType, @NotNull JetCallExpression callExpression, TypeInferenceContext context) {
TypeInferenceContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE);
JetExpression calleeExpression = callExpression.getCalleeExpression(); JetExpression calleeExpression = callExpression.getCalleeExpression();
if (calleeExpression == null) { if (calleeExpression == null) {
return null; return null;
@@ -2278,14 +2269,13 @@ public class JetTypeInferrer {
} }
@Override @Override
public JetType visitUnaryExpression(JetUnaryExpression expression, TypeInferenceContext contextWithExpectedType) { public JetType visitUnaryExpression(JetUnaryExpression expression, TypeInferenceContext context) {
TypeInferenceContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE);
JetExpression baseExpression = expression.getBaseExpression(); JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression == null) return null; if (baseExpression == null) return null;
JetSimpleNameExpression operationSign = expression.getOperationSign(); JetSimpleNameExpression operationSign = expression.getOperationSign();
if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) { if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) {
// TODO : Some processing for the label? // TODO : Some processing for the label?
return context.services.checkType(getType(baseExpression, context.replaceExpectedReturnType(contextWithExpectedType.expectedType)), expression, contextWithExpectedType); return context.services.checkType(getType(baseExpression, context.replaceExpectedReturnType(context.expectedType)), expression, context);
} }
IElementType operationType = operationSign.getReferencedNameElementType(); IElementType operationType = operationSign.getReferencedNameElementType();
String name = unaryOperationNames.get(operationType); String name = unaryOperationNames.get(operationType);
@@ -2293,7 +2283,7 @@ public class JetTypeInferrer {
context.trace.getErrorHandler().genericError(operationSign.getNode(), "Unknown unary operation"); context.trace.getErrorHandler().genericError(operationSign.getNode(), "Unknown unary operation");
return null; return null;
} }
JetType receiverType = getType(context.scope, baseExpression, false, context); JetType receiverType = getType(context.scope, baseExpression, false, context.replaceExpectedType(NO_EXPECTED_TYPE));
if (receiverType == null) return null; if (receiverType == null) return null;
FunctionDescriptor functionDescriptor = context.services.lookupFunction(context.scope, expression.getOperationSign(), name, receiverType, Collections.<JetType>emptyList(), true); FunctionDescriptor functionDescriptor = context.services.lookupFunction(context.scope, expression.getOperationSign(), name, receiverType, Collections.<JetType>emptyList(), true);
if (functionDescriptor == null) return null; if (functionDescriptor == null) return null;
@@ -2317,7 +2307,7 @@ public class JetTypeInferrer {
else { else {
result = returnType; result = returnType;
} }
return context.services.checkType(result, expression, contextWithExpectedType); return context.services.checkType(result, expression, context);
} }
@Override @Override
@@ -2642,9 +2632,9 @@ public class JetTypeInferrer {
} }
@Override @Override
protected LookupResult furtherNameLookup(@NotNull JetSimpleNameExpression expression, @NotNull String referencedName, TypeInferenceContext context) { protected boolean furtherNameLookup(@NotNull JetSimpleNameExpression expression, @NotNull String referencedName, @NotNull JetType[] result, TypeInferenceContext context) {
JetType result = lookupNamespaceType(expression, referencedName, context); result[0] = lookupNamespaceType(expression, referencedName, context);
return new LookupResult(result, result != null); return result[0] != null;
} }
} }
@@ -26,13 +26,7 @@ public class DescriptorRenderer {
} }
public static final DescriptorRenderer TEXT = new DescriptorRenderer(); public static final DescriptorRenderer TEXT = new DescriptorRenderer();
//TODO remove TEXT_FOR_DEBUG
public static final DescriptorRenderer TEXT_FOR_DEBUG = new DescriptorRenderer() {
@Override
public String renderType(JetType type) {
return String.valueOf(type);
}
};
public static final DescriptorRenderer HTML = new DescriptorRenderer() { public static final DescriptorRenderer HTML = new DescriptorRenderer() {
@Override @Override