public MemberAccessExpressionNode getLastMAEInChain(MemberAccessExpressionNode node) { while (node.getRightOperandNode() instanceof MemberAccessExpressionNode) node = (MemberAccessExpressionNode)node.getRightOperandNode(); return node; }
/** * Explore a MemberAccessNode and * decide if it is a reference * to a package. * * This method will always return a result less than what isDottedName will return, * as package name must "win" over dotted name. */ int isPackageName(IASNode n) { int result = Integer.MAX_VALUE; if ( n instanceof MemberAccessExpressionNode ) { MemberAccessExpressionNode ma = (MemberAccessExpressionNode)n; if(ma.isPackageReference()) // This needs to be less than the value returned from isDottedName, // so that isPackageName wins result = 1; } return result; }
/** * Explore a MemberAccessNode and decide if * its stem is a referenceto a package. * @return a "feasible" cost of this node * is of the form foo.bar, where foo is a package. */ public static int isDottedName(IASNode n) { if ( n instanceof MemberAccessExpressionNode && ((MemberAccessExpressionNode)n).stemIsPackage() ) return 1; // Return "unfeasible" cost. return Integer.MAX_VALUE; }
private String buildChain(MemberAccessExpressionNode mae) { IExpressionNode left = mae.getLeftOperandNode(); if (left.getNodeID() == ASTNodeID.IdentifierID) { IExpressionNode right = mae.getRightOperandNode(); if (right.getNodeID() == ASTNodeID.IdentifierID) { return ((IdentifierNode)left).getName() + "." + ((IdentifierNode)right).getName(); } } else if (left.getNodeID() == ASTNodeID.MemberAccessExpressionID) { IExpressionNode right = mae.getRightOperandNode(); if (right.getNodeID() == ASTNodeID.IdentifierID) { String l = buildChain((MemberAccessExpressionNode)left); if (l == null) return null; return l + "." + ((IdentifierNode)right).getName(); } } return null; } }
IExpressionNode left = node.getLeftOperandNode(); if (left instanceof FunctionCallNode) // probably a cast s = getSourceStringFromIdentifierNode((IdentifierNode)left); else System.out.println("expected binding member access left node" + node.toString()); s += "."; IExpressionNode right = node.getRightOperandNode(); if (right instanceof FunctionCallNode) // probably a cast s += getSourceStringFromIdentifierNode((IdentifierNode)right); else System.out.println("expected binding member access right node" + node.toString());
/** * Check if the node is for {@code super(this)} but not * {@code super(this).call()}. The incoming tree shape is: * * <pre> * MemberAccessExpressionID(FunctionCallID(SuperID(void), ContainerID(IdentifierID(void))), qname) * </pre> * * @return "0" if the node represents {@code super(this)}; * {@link Integer#MAX_VALUE} otherwise. */ public static int isSuperThisForFieldAccess(IASNode n) { // super(this).callSomething() is handled by another pattern that emits // "callsuper" instruction. if (n.getParent() instanceof FunctionCallNode) return Integer.MAX_VALUE; // The following unguarded casts are safe, because this is a cost // function and the pattern matcher has checked all the node IDs. final MemberAccessExpressionNode memberAccessNode = (MemberAccessExpressionNode)n; final FunctionCallNode callNode = (FunctionCallNode)memberAccessNode.getLeftOperandNode(); final IdentifierNode idNode = (IdentifierNode)callNode.getArgumentsNode().getChild(0); if (idNode.getName().equals(IASKeywordConstants.THIS)) return 1; else return Integer.MAX_VALUE; }
if ( maex.stemIsPackage() && maex.getLeftOperandNode() instanceof IdentifierNode ) ((IdentifierNode)maex.getLeftOperandNode()).getName() );
IExpressionNode maRight = ((MemberAccessExpressionNode)left).getRightOperandNode(); if (maRight instanceof NamespaceIdentifierNode) ((MemberAccessExpressionNode)left).setRightOperandNode(new NamespaceAccessExpressionNode((NamespaceIdentifierNode)maRight, op, right)); ((MemberAccessExpressionNode)left).setRightOperandNode(new NamespaceAccessExpressionNode(new NamespaceIdentifierNode((IdentifierNode)maRight), op, right)); ((MemberAccessExpressionNode)left).setRightOperandNode(new NamespaceAccessExpressionNode(new QualifiedNamespaceExpressionNode((MemberAccessExpressionNode)maRight), op, right));
IDefinition def = mae.resolve(project); if (def != null && def.isPublic() && (def instanceof IAccessorDefinition || def instanceof IVariableDefinition)) IExpressionNode leftSide = mae.getLeftOperandNode(); if (leftSide instanceof IIdentifierNode)
@Override String computeSimpleReference() { return getDisplayString(); }
/** * If the {@code node} is a {@link FullNameNode}, recursively convert its * subtree into {@link MemberAccessExpressionNode}. Otherwise, return * {@code node}. * * @param node Expression node. * @return If {@code node} is a {@link FullNameNode}, the result is a * {@link MemberAccessExpressionNode}; Otherwise, {@code node} is returned * unchanged. */ public static ExpressionNodeBase toMemberAccessExpressionNode(final ExpressionNodeBase node) { if (node instanceof FullNameNode) { final FullNameNode fullnameNode = (FullNameNode)node; final ExpressionNodeBase left = toMemberAccessExpressionNode(fullnameNode.leftOperandNode); final ExpressionNodeBase right = toMemberAccessExpressionNode(fullnameNode.rightOperandNode); final MemberAccessExpressionNode result = new MemberAccessExpressionNode(left, null, right); result.operatorStart = fullnameNode.operatorStart; result.setHasParenthesis(fullnameNode.hasParenthesis()); return result; } else { return node; } }
final IDefinition def = func_name.resolve(project); if ( def instanceof InterfaceDefinition ) addProblem(new UnresolvedClassReferenceProblem(call_node, func_name.getDisplayString()));
@Override protected MemberAccessExpressionNode copy() { return new MemberAccessExpressionNode(this); }
@Override public String getOperatorText() { switch (getNodeID()) { case E4XFilterID: return ".()"; default: return super.getOperatorText(); } }
@Override boolean isPartOfMemberRef(ExpressionNodeBase e) { // If e is the rhs, then this it is always a member ref. // If e is the lhs, then it is a member ref // if the MemberAccessExpression is a member ref. if (e == this.rightOperandNode) { return true; } else if (e == this.leftOperandNode) { IASNode p = getParent(); if (p instanceof ExpressionNodeBase) return ((ExpressionNodeBase)p).isPartOfMemberRef(this); } return false; }
@Override public ASTNodeID getNodeID() { final ASTNodeID nodeID; if (getOperator() == OperatorType.DESCENDANT_ACCESS) { nodeID = ASTNodeID.Op_DescendantsID; } else if (rightOperandNode != null && rightOperandNode.hasParenthesis()) { nodeID = ASTNodeID.E4XFilterID; } else { nodeID = ASTNodeID.MemberAccessExpressionID; } return nodeID; }
public ICompilerProblem isMissingMember(IASNode iNode) { if (iNode instanceof IdentifierNode && iNode.getParent() instanceof MemberAccessExpressionNode) { MemberAccessExpressionNode mae = (MemberAccessExpressionNode)(iNode.getParent()); if (iNode == mae.getRightOperandNode()) { ITypeDefinition leftDef = mae.getLeftOperandNode().resolveType(project); if (!leftDef.isDynamic()) return new AccessUndefinedMemberProblem(iNode, ((IdentifierNode)iNode).getName(), leftDef.getQualifiedName()); } } return null; }
IExpressionNode left = node.getLeftOperandNode(); if (left instanceof FunctionCallNode) // probably a cast s = getSourceStringFromIdentifierNode((IdentifierNode)left); else System.out.println("expected binding BinaryOperatorAsNode left node" + node.toString()); System.out.println("expected binding member access left node" + node.toString()); s += "."; IExpressionNode right = node.getRightOperandNode(); if (right instanceof FunctionCallNode) // probably a cast s += getSourceStringFromIdentifierNode((IdentifierNode)right); else System.out.println("expected binding member access right node" + node.toString());
/** * Check if the node is for {@code super(this)} but not * {@code super(this).call()}. The incoming tree shape is: * * <pre> * MemberAccessExpressionID(FunctionCallID(SuperID(void), ContainerID(IdentifierID(void))), qname) * </pre> * * @return "0" if the node represents {@code super(this)}; * {@link Integer#MAX_VALUE} otherwise. */ public static int isSuperThisForFieldAccess(IASNode n) { // super(this).callSomething() is handled by another pattern that emits // "callsuper" instruction. if (n.getParent() instanceof FunctionCallNode) return Integer.MAX_VALUE; // The following unguarded casts are safe, because this is a cost // function and the pattern matcher has checked all the node IDs. final MemberAccessExpressionNode memberAccessNode = (MemberAccessExpressionNode)n; final FunctionCallNode callNode = (FunctionCallNode)memberAccessNode.getLeftOperandNode(); final IdentifierNode idNode = (IdentifierNode)callNode.getArgumentsNode().getChild(0); if (idNode.getName().equals(IASKeywordConstants.THIS)) return 1; else return Integer.MAX_VALUE; }
if ( maex.stemIsPackage() && maex.getLeftOperandNode() instanceof IdentifierNode ) ((IdentifierNode)maex.getLeftOperandNode()).getName() );