Receiver visitor added

This commit is contained in:
Andrey Breslav
2011-09-20 06:43:07 -05:00
parent 6ede1a342f
commit ee430f1698
7 changed files with 55 additions and 1 deletions
@@ -6,7 +6,7 @@ import org.jetbrains.jet.lang.types.JetType;
/** /**
* @author abreslav * @author abreslav
*/ */
public class AbstractReceiverDescriptor implements ReceiverDescriptor { public abstract class AbstractReceiverDescriptor implements ReceiverDescriptor {
protected final JetType receiverType; protected final JetType receiverType;
public AbstractReceiverDescriptor(@NotNull JetType receiverType) { public AbstractReceiverDescriptor(@NotNull JetType receiverType) {
@@ -1,5 +1,6 @@
package org.jetbrains.jet.lang.resolve.scopes.receivers; package org.jetbrains.jet.lang.resolve.scopes.receivers;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
/** /**
@@ -10,4 +11,9 @@ public class ClassReceiver extends ImplicitReceiverDescriptor {
public ClassReceiver(ClassDescriptor classDescriptor) { public ClassReceiver(ClassDescriptor classDescriptor) {
super(classDescriptor, classDescriptor.getDefaultType()); super(classDescriptor, classDescriptor.getDefaultType());
} }
@Override
public <R, D> R accept(@NotNull ReceiverDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitClassReceiver(this, data);
}
} }
@@ -20,4 +20,9 @@ public class ExpressionReceiver extends AbstractReceiverDescriptor implements Re
public JetExpression getExpression() { public JetExpression getExpression() {
return expression; return expression;
} }
@Override
public <R, D> R accept(@NotNull ReceiverDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitExpressionReceiver(this, data);
}
} }
@@ -12,4 +12,9 @@ public class ExtensionReceiver extends ImplicitReceiverDescriptor {
public ExtensionReceiver(@NotNull CallableDescriptor callableDescriptor, @NotNull JetType receiverType) { public ExtensionReceiver(@NotNull CallableDescriptor callableDescriptor, @NotNull JetType receiverType) {
super(callableDescriptor, receiverType); super(callableDescriptor, receiverType);
} }
@Override
public <R, D> R accept(@NotNull ReceiverDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitExtensionReceiver(this, data);
}
} }
@@ -20,6 +20,11 @@ public interface ReceiverDescriptor {
return false; return false;
} }
@Override
public <R, D> R accept(@NotNull ReceiverDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitNoReceiver(this, data);
}
@Override @Override
public String toString() { public String toString() {
return "NO_RECEIVER"; return "NO_RECEIVER";
@@ -30,4 +35,6 @@ public interface ReceiverDescriptor {
JetType getType(); JetType getType();
boolean exists(); boolean exists();
<R, D> R accept(@NotNull ReceiverDescriptorVisitor<R, D> visitor, D data);
} }
@@ -0,0 +1,26 @@
package org.jetbrains.jet.lang.resolve.scopes.receivers;
/**
* @author abreslav
*/
public class ReceiverDescriptorVisitor<R, D> {
public R visitNoReceiver(ReceiverDescriptor noReceiver, D data) {
return null;
}
public R visitTransientReceiver(TransientReceiver receiver, D data) {
return null;
}
public R visitExtensionReceiver(ExtensionReceiver receiver, D data) {
return null;
}
public R visitExpressionReceiver(ExpressionReceiver receiver, D data) {
return null;
}
public R visitClassReceiver(ClassReceiver classReceiver, D data) {
return null;
}
}
@@ -13,4 +13,9 @@ public class TransientReceiver extends AbstractReceiverDescriptor {
public TransientReceiver(@NotNull JetType type) { public TransientReceiver(@NotNull JetType type) {
super(type); super(type);
} }
@Override
public <R, D> R accept(@NotNull ReceiverDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitTransientReceiver(this, data);
}
} }