Support for local objects
This commit is contained in:
@@ -595,22 +595,6 @@ public class JetControlFlowProcessor {
|
|||||||
builder.read(expression);
|
builder.read(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitObjectLiteralExpression(JetObjectLiteralExpression expression) {
|
|
||||||
List<JetDelegationSpecifier> delegationSpecifiers = expression.getObjectDeclaration().getDelegationSpecifiers();
|
|
||||||
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
|
|
||||||
if (delegationSpecifier instanceof JetDelegatorByExpressionSpecifier) {
|
|
||||||
JetDelegatorByExpressionSpecifier specifier = (JetDelegatorByExpressionSpecifier) delegationSpecifier;
|
|
||||||
JetExpression delegateExpression = specifier.getDelegateExpression();
|
|
||||||
if (delegateExpression != null) {
|
|
||||||
value(delegateExpression, false, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.read(expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitIsExpression(JetIsExpression expression) {
|
public void visitIsExpression(JetIsExpression expression) {
|
||||||
value(expression.getLeftHandSide(), false, inCondition);
|
value(expression.getLeftHandSide(), false, inCondition);
|
||||||
@@ -720,6 +704,32 @@ public class JetControlFlowProcessor {
|
|||||||
builder.bindLabel(doneLabel);
|
builder.bindLabel(doneLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitObjectLiteralExpression(JetObjectLiteralExpression expression) {
|
||||||
|
// List<JetDelegationSpecifier> delegationSpecifiers = expression.getObjectDeclaration().getDelegationSpecifiers();
|
||||||
|
// for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
|
||||||
|
// if (delegationSpecifier instanceof JetDelegatorByExpressionSpecifier) {
|
||||||
|
// JetDelegatorByExpressionSpecifier specifier = (JetDelegatorByExpressionSpecifier) delegationSpecifier;
|
||||||
|
// JetExpression delegateExpression = specifier.getDelegateExpression();
|
||||||
|
// if (delegateExpression != null) {
|
||||||
|
// value(delegateExpression, false, false);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
value(expression.getObjectDeclaration(), false, inCondition);
|
||||||
|
builder.read(expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
||||||
|
for (JetDelegationSpecifier delegationSpecifier : declaration.getDelegationSpecifiers()) {
|
||||||
|
value(delegationSpecifier, false, inCondition);
|
||||||
|
}
|
||||||
|
for (JetDeclaration jetDeclaration : declaration.getDeclarations()) {
|
||||||
|
FOR_LOCAL_CLASSES.value(jetDeclaration, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitTypeProjection(JetTypeProjection typeProjection) {
|
public void visitTypeProjection(JetTypeProjection typeProjection) {
|
||||||
// TODO : Support Type Arguments. Class object may be initialized at this point");
|
// TODO : Support Type Arguments. Class object may be initialized at this point");
|
||||||
@@ -730,4 +740,11 @@ public class JetControlFlowProcessor {
|
|||||||
builder.unsupported(element);
|
builder.unsupported(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final CFPVisitor FOR_LOCAL_CLASSES = new CFPVisitor(false, false) {
|
||||||
|
@Override
|
||||||
|
public void visitFunction(JetFunction function) {
|
||||||
|
// Nothing
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -44,6 +44,6 @@ public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return DescriptorRenderer.TEXT.render(this) + "[" + getClass().getCanonicalName() + "@" + System.identityHashCode(this) + "]";
|
return DescriptorRenderer.TEXT_FOR_DEBUG.render(this) + "[" + getClass().getCanonicalName() + "@" + System.identityHashCode(this) + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public interface BindingContext {
|
|||||||
VariableDescriptor getVariableDescriptor(JetParameter declaration);
|
VariableDescriptor getVariableDescriptor(JetParameter declaration);
|
||||||
|
|
||||||
PropertyDescriptor getPropertyDescriptor(JetParameter primaryConstructorParameter);
|
PropertyDescriptor getPropertyDescriptor(JetParameter primaryConstructorParameter);
|
||||||
|
PropertyDescriptor getPropertyDescriptor(JetObjectDeclarationName objectDeclarationName);
|
||||||
|
|
||||||
JetType getExpressionType(JetExpression expression);
|
JetType getExpressionType(JetExpression expression);
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,11 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
|
|||||||
return primaryConstructorParameterDeclarationsToPropertyDescriptors.get(primaryConstructorParameter);
|
return primaryConstructorParameterDeclarationsToPropertyDescriptors.get(primaryConstructorParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PropertyDescriptor getPropertyDescriptor(JetObjectDeclarationName objectDeclarationName) {
|
||||||
|
return (PropertyDescriptor) declarationsToDescriptors.get(objectDeclarationName);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public ConstructorDescriptor getConstructorDescriptor(@NotNull JetElement declaration) {
|
public ConstructorDescriptor getConstructorDescriptor(@NotNull JetElement declaration) {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ public class DeferredType implements JetType {
|
|||||||
this.lazyValue = lazyValue;
|
this.lazyValue = lazyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isComputed() {
|
||||||
|
return lazyValue.isComputed();
|
||||||
|
}
|
||||||
|
|
||||||
public JetType getActualType() {
|
public JetType getActualType() {
|
||||||
return lazyValue.get();
|
return lazyValue.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1870,6 +1870,17 @@ public class JetTypeInferrer {
|
|||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
||||||
|
TopDownAnalyzer topDownAnalyzer = new TopDownAnalyzer(semanticServices, trace);
|
||||||
|
topDownAnalyzer.processObject(scope, scope.getContainingDeclaration(), declaration);
|
||||||
|
ClassDescriptor classDescriptor = trace.getBindingContext().getClassDescriptor(declaration);
|
||||||
|
if (classDescriptor != null) {
|
||||||
|
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(scope.getContainingDeclaration(), declaration, classDescriptor);
|
||||||
|
scope.addVariableDescriptor(propertyDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitProperty(JetProperty property) {
|
public void visitProperty(JetProperty property) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package org.jetbrains.jet.lang.types;
|
package org.jetbrains.jet.lang.types;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
@@ -19,8 +17,8 @@ public abstract class LazyValue<T> {
|
|||||||
|
|
||||||
protected abstract T compute();
|
protected abstract T compute();
|
||||||
|
|
||||||
public State getState() {
|
public boolean isComputed() {
|
||||||
return state;
|
return state == State.ERROR || state == State.COMPUTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final T get() {
|
public final T get() {
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ public class DescriptorRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final DescriptorRenderer TEXT = new DescriptorRenderer();
|
public static final DescriptorRenderer TEXT = new DescriptorRenderer();
|
||||||
|
public static final DescriptorRenderer TEXT_FOR_DEBUG = new DescriptorRenderer() {
|
||||||
|
@Override
|
||||||
|
public String renderType(JetType type) {
|
||||||
|
if (type instanceof DeferredType) {
|
||||||
|
DeferredType deferredType = (DeferredType) type;
|
||||||
|
if (!deferredType.isComputed()) return "<Deferred>";
|
||||||
|
}
|
||||||
|
return "" + type;
|
||||||
|
}
|
||||||
|
};
|
||||||
public static final DescriptorRenderer HTML = new DescriptorRenderer() {
|
public static final DescriptorRenderer HTML = new DescriptorRenderer() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,6 +78,10 @@ public class DescriptorRenderer {
|
|||||||
return keyword;
|
return keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String renderType(JetType type) {
|
||||||
|
return "" + type;
|
||||||
|
}
|
||||||
|
|
||||||
protected String escape(String s) {
|
protected String escape(String s) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@@ -139,25 +153,25 @@ public class DescriptorRenderer {
|
|||||||
if (inType != null && outType != null) {
|
if (inType != null && outType != null) {
|
||||||
builder.append(renderKeyword("var")).append(" ");
|
builder.append(renderKeyword("var")).append(" ");
|
||||||
if (inType.equals(outType)) {
|
if (inType.equals(outType)) {
|
||||||
typeString = outType.toString();
|
typeString = renderType(outType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
typeString = "<" + renderKeyword("in") + ": " + inType + " " + renderKeyword("out") + ": " + outType + ">";
|
typeString = "<" + renderKeyword("in") + ": " + renderType(inType) + " " + renderKeyword("out") + ": " + renderType(outType) + ">";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (outType != null) {
|
else if (outType != null) {
|
||||||
builder.append(renderKeyword("val")).append(" ");
|
builder.append(renderKeyword("val")).append(" ");
|
||||||
typeString = outType.toString();
|
typeString = renderType(outType);
|
||||||
}
|
}
|
||||||
else if (inType != null) {
|
else if (inType != null) {
|
||||||
builder.append(lt()).append("write-only> ");
|
builder.append(lt()).append("write-only> ");
|
||||||
typeString = inType.toString();
|
typeString = renderType(inType);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderTypeParameters(typeParameters, builder);
|
renderTypeParameters(typeParameters, builder);
|
||||||
|
|
||||||
if (receiverType != null) {
|
if (receiverType != null) {
|
||||||
builder.append(escape(receiverType.toString())).append(".");
|
builder.append(escape(renderType(receiverType))).append(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeString;
|
return typeString;
|
||||||
@@ -183,7 +197,7 @@ public class DescriptorRenderer {
|
|||||||
|
|
||||||
JetType receiverType = descriptor.getReceiverType();
|
JetType receiverType = descriptor.getReceiverType();
|
||||||
if (receiverType != null) {
|
if (receiverType != null) {
|
||||||
builder.append(escape(receiverType.toString())).append(".");
|
builder.append(escape(renderType(receiverType))).append(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
renderName(descriptor, builder);
|
renderName(descriptor, builder);
|
||||||
@@ -195,7 +209,7 @@ public class DescriptorRenderer {
|
|||||||
builder.append(", ");
|
builder.append(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.append(") : ").append(escape(descriptor.getUnsubstitutedReturnType().toString()));
|
builder.append(") : ").append(escape(renderType(descriptor.getUnsubstitutedReturnType())));
|
||||||
return super.visitFunctionDescriptor(descriptor, builder);
|
return super.visitFunctionDescriptor(descriptor, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +258,7 @@ public class DescriptorRenderer {
|
|||||||
builder.append(" : ");
|
builder.append(" : ");
|
||||||
for (Iterator<? extends JetType> iterator = supertypes.iterator(); iterator.hasNext(); ) {
|
for (Iterator<? extends JetType> iterator = supertypes.iterator(); iterator.hasNext(); ) {
|
||||||
JetType supertype = iterator.next();
|
JetType supertype = iterator.next();
|
||||||
builder.append(supertype);
|
builder.append(renderType(supertype));
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
builder.append(", ");
|
builder.append(", ");
|
||||||
}
|
}
|
||||||
@@ -261,7 +275,7 @@ public class DescriptorRenderer {
|
|||||||
if (!descriptor.getUpperBounds().isEmpty()) {
|
if (!descriptor.getUpperBounds().isEmpty()) {
|
||||||
JetType bound = descriptor.getUpperBounds().iterator().next();
|
JetType bound = descriptor.getUpperBounds().iterator().next();
|
||||||
if (bound != JetStandardClasses.getAnyType()) {
|
if (bound != JetStandardClasses.getAnyType()) {
|
||||||
builder.append(" : ").append(bound);
|
builder.append(" : ").append(renderType(bound));
|
||||||
if (descriptor.getUpperBounds().size() > 1) {
|
if (descriptor.getUpperBounds().size() > 1) {
|
||||||
builder.append(" (...)");
|
builder.append(" (...)");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,3 +57,27 @@ namespace nestedObejcts {
|
|||||||
val d = A.B.A
|
val d = A.B.A
|
||||||
val e = B.<error>A</error>.B
|
val e = B.<error>A</error>.B
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace localObjects {
|
||||||
|
object A {
|
||||||
|
val x : Int
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
fun foo() : Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
A.x
|
||||||
|
val b = object : Foo {
|
||||||
|
}
|
||||||
|
b.foo()
|
||||||
|
|
||||||
|
object B {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
B.foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
val bb = <error>B</error>.foo()
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
namespace localObjects {
|
||||||
|
object ~A~A {
|
||||||
|
~x~val x : Int
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
~foo()~fun foo() : Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
`A`A.`x`x
|
||||||
|
val b = object : Foo {
|
||||||
|
}
|
||||||
|
b.`foo()`foo()
|
||||||
|
|
||||||
|
object ~B~B {
|
||||||
|
~B.foo()~fun foo() {}
|
||||||
|
}
|
||||||
|
`B`B.`B.foo()`foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
val bb = `!`B.foo()
|
||||||
|
}
|
||||||
@@ -128,6 +128,11 @@ public class JetTestUtils {
|
|||||||
throw new UnsupportedOperationException(); // TODO
|
throw new UnsupportedOperationException(); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PropertyDescriptor getPropertyDescriptor(JetObjectDeclarationName objectDeclarationName) {
|
||||||
|
throw new UnsupportedOperationException(); // TODO
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetType getExpressionType(JetExpression expression) {
|
public JetType getExpressionType(JetExpression expression) {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
throw new UnsupportedOperationException(); // TODO
|
||||||
|
|||||||
Reference in New Issue
Block a user