1 21 package oracle.toplink.essentials.internal.parsing; 23 24 33 import oracle.toplink.essentials.expressions.*; 34 35 public class MemberOfNode extends BinaryOperatorNode { 36 private boolean notIndicated = false; 37 38 private Expression leftExpression = null; 43 44 47 public MemberOfNode() { 48 super(); 49 } 50 51 55 public void makeNodeOneToMany(Node theNode) { 56 Node currentNode = theNode; 57 do { 58 if (!currentNode.hasRight()) { 59 ((AttributeNode)currentNode).setRequiresCollectionAttribute(true); 60 return; 61 } 62 currentNode = currentNode.getRight(); 63 } while (true); 64 } 65 66 70 public void validate(ParseTreeContext context) { 71 super.validate(context); 72 Node left = getLeft(); 73 if (left.isVariableNode() && ((VariableNode)left).isAlias(context)) { 74 context.usedVariable(((VariableNode)left).getCanonicalVariableName()); 75 } 76 left.validateParameter(context, right.getType()); 77 TypeHelper typeHelper = context.getTypeHelper(); 78 setType(typeHelper.getBooleanType()); 79 } 80 81 public Expression generateExpression(GenerationContext context) { 82 if (getLeft().isVariableNode() && ((VariableNode)getLeft()).isAlias(context)) { 86 VariableNode leftVariableNode = (VariableNode)getLeft(); 87 makeNodeOneToMany(getRight()); 88 return getRight().generateExpression(context).equal(new ExpressionBuilder(leftVariableNode.resolveClass(context))); 89 } 90 91 if (getRight().isParameterNode()) { 93 makeNodeOneToMany(getLeft()); 94 } else { 95 makeNodeOneToMany(getRight()); 96 } 97 98 if (notIndicated()) { 100 Expression resultFromRight = null; 101 context.setMemberOfNode(this); 102 this.setLeftExpression(getLeft().generateExpression(context)); 103 resultFromRight = getRight().generateExpression(context); 104 context.setMemberOfNode(null); 106 this.setLeftExpression(null); 107 return resultFromRight; 108 } else { 109 return getRight().generateExpression(context).equal(getLeft().generateExpression(context)); 111 } 112 } 113 114 120 public void indicateNot() { 121 notIndicated = true; 122 } 123 124 public boolean notIndicated() { 125 return notIndicated; 126 } 127 128 public void setLeftExpression(Expression newLeftExpression) { 130 leftExpression = newLeftExpression; 131 } 132 133 public Expression getLeftExpression() { 134 return leftExpression; 135 } 136 } 137 | Popular Tags |