Common superinterface for JetBinaryOperation and JetUnaryOperation

This commit is contained in:
Andrey Breslav
2011-12-02 20:05:32 +03:00
parent 3b8d33d278
commit d3abbc5b56
13 changed files with 29 additions and 17 deletions
@@ -1830,7 +1830,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
@Override
public StackValue visitPrefixExpression(JetPrefixExpression expression, StackValue receiver) {
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationSign());
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
final Callable callable = resolveToCallable(op, false);
if (callable instanceof IntrinsicMethod) {
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
@@ -1847,7 +1847,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
@Override
public StackValue visitPostfixExpression(JetPostfixExpression expression, StackValue receiver) {
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationSign());
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
if (op instanceof FunctionDescriptor) {
final Type asmType = expressionType(expression);
DeclarationDescriptor cls = op.getContainingDeclaration();
@@ -14,7 +14,6 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -284,7 +283,7 @@ public class JetControlFlowProcessor {
@Override
public void visitUnaryExpression(JetUnaryExpression expression) {
JetSimpleNameExpression operationSign = expression.getOperationSign();
JetSimpleNameExpression operationSign = expression.getOperationReference();
IElementType operationType = operationSign.getReferencedNameElementType();
JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression == null) return;
@@ -286,7 +286,7 @@ public class JetFlowInformationProvider {
operationReference = ((JetBinaryExpression) parent).getOperationReference();
}
else if (parent instanceof JetUnaryExpression) {
operationReference = ((JetUnaryExpression) parent).getOperationSign();
operationReference = ((JetUnaryExpression) parent).getOperationReference();
}
if (operationReference != null) {
DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, operationReference);
@@ -471,7 +471,7 @@ public class JetFlowInformationProvider {
}
}
else if (element instanceof JetPostfixExpression) {
IElementType operationToken = ((JetPostfixExpression) element).getOperationSign().getReferencedNameElementType();
IElementType operationToken = ((JetPostfixExpression) element).getOperationReference().getReferencedNameElementType();
if (operationToken == JetTokens.PLUSPLUS || operationToken == JetTokens.MINUSMINUS) {
trace.report(Errors.UNUSED_CHANGED_VALUE.on(element, element));
}
@@ -10,7 +10,7 @@ import org.jetbrains.jet.JetNodeTypes;
/**
* @author max
*/
public class JetBinaryExpression extends JetExpression {
public class JetBinaryExpression extends JetExpression implements JetOperationExpression {
public JetBinaryExpression(@NotNull ASTNode node) {
super(node);
}
@@ -46,6 +46,7 @@ public class JetBinaryExpression extends JetExpression {
return null;
}
@Override
@NotNull
public JetSimpleNameExpression getOperationReference() {
return (JetSimpleNameExpression) findChildByType(JetNodeTypes.OPERATION_REFERENCE);
@@ -65,7 +65,7 @@ public class JetCallExpression extends JetExpression implements JetCallElement {
}
else if (psi instanceof JetPrefixExpression) {
JetPrefixExpression prefixExpression = (JetPrefixExpression) psi;
if (JetTokens.LABELS.contains(prefixExpression.getOperationSign().getReferencedNameElementType())) {
if (JetTokens.LABELS.contains(prefixExpression.getOperationReference().getReferencedNameElementType())) {
JetExpression labeledExpression = prefixExpression.getBaseExpression();
if (labeledExpression instanceof JetFunctionLiteralExpression) {
result.add(labeledExpression);
@@ -0,0 +1,11 @@
package org.jetbrains.jet.lang.psi;
import org.jetbrains.annotations.NotNull;
/**
* @author abreslav
*/
public interface JetOperationExpression {
@NotNull
JetSimpleNameExpression getOperationReference();
}
@@ -25,7 +25,7 @@ public class JetPrefixExpression extends JetUnaryExpression {
@Nullable @IfNotParsed
public JetExpression getBaseExpression() {
PsiElement expression = getOperationSign().getNextSibling();
PsiElement expression = getOperationReference().getNextSibling();
while (expression != null && !(expression instanceof JetExpression)) {
expression = expression.getNextSibling();
}
@@ -26,7 +26,7 @@ public class JetPsiUtil {
}
}
else if (expression instanceof JetPrefixExpression) {
if (JetTokens.LABELS.contains(((JetPrefixExpression) expression).getOperationSign().getReferencedNameElementType())) {
if (JetTokens.LABELS.contains(((JetPrefixExpression) expression).getOperationReference().getReferencedNameElementType())) {
JetExpression baseExpression = ((JetPrefixExpression) expression).getBaseExpression();
if (baseExpression != null) {
expression = baseExpression;
@@ -8,7 +8,7 @@ import org.jetbrains.jet.JetNodeTypes;
/**
* @author abreslav
*/
public abstract class JetUnaryExpression extends JetExpression {
public abstract class JetUnaryExpression extends JetExpression implements JetOperationExpression {
public JetUnaryExpression(ASTNode node) {
super(node);
}
@@ -16,8 +16,9 @@ public abstract class JetUnaryExpression extends JetExpression {
@Nullable @IfNotParsed
public abstract JetExpression getBaseExpression();
@Override
@NotNull
public JetSimpleNameExpression getOperationSign() {
public JetSimpleNameExpression getOperationReference() {
return (JetSimpleNameExpression) findChildByType(JetNodeTypes.OPERATION_REFERENCE);
}
}
@@ -162,7 +162,7 @@ public class CallMaker {
}
public static Call makeCall(@NotNull ReceiverDescriptor baseAsReceiver, JetUnaryExpression expression) {
return makeCall(expression, baseAsReceiver, null, expression.getOperationSign(), Collections.<ValueArgument>emptyList());
return makeCall(expression, baseAsReceiver, null, expression.getOperationReference(), Collections.<ValueArgument>emptyList());
}
public static Call makeArraySetCall(@NotNull ReceiverDescriptor arrayAsReceiver, JetArrayAccessExpression arrayAccessExpression, JetExpression rightHandSide) {
@@ -628,7 +628,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
public JetType visitUnaryExpression(JetUnaryExpression expression, ExpressionTypingContext context) {
JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression == null) return null;
JetSimpleNameExpression operationSign = expression.getOperationSign();
JetSimpleNameExpression operationSign = expression.getOperationReference();
if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) {
String referencedName = operationSign.getReferencedName();
referencedName = referencedName == null ? " <?>" : referencedName;
@@ -649,7 +649,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
FunctionDescriptor functionDescriptor = context.resolveCallWithGivenNameToDescriptor(
CallMaker.makeCall(receiver, expression),
expression.getOperationSign(),
expression.getOperationReference(),
name);
if (functionDescriptor == null) return null;
@@ -109,7 +109,7 @@ public class DataFlowUtils {
@Override
public void visitUnaryExpression(JetUnaryExpression expression) {
IElementType operationTokenType = expression.getOperationSign().getReferencedNameElementType();
IElementType operationTokenType = expression.getOperationReference().getReferencedNameElementType();
if (operationTokenType == JetTokens.EXCL) {
JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression != null) {
@@ -20,7 +20,7 @@ public class LabelsAnnotator implements Annotator {
element.accept(new JetVisitorVoid() {
@Override
public void visitPrefixExpression(JetPrefixExpression expression) {
JetSimpleNameExpression operationSign = expression.getOperationSign();
JetSimpleNameExpression operationSign = expression.getOperationReference();
if (JetTokens.LABELS.contains(operationSign.getReferencedNameElementType())) {
holder.createInfoAnnotation(operationSign, null).setTextAttributes(JetHighlighter.JET_LABEL_IDENTIFIER);
}