@Override public boolean enterBinaryNode(BinaryNode binaryNode) { if (!binaryNode.isAssignment()) { if (isResultString(binaryNode)) { add(STRING_TYPE); return false; TokenType tokenType = binaryNode.tokenType(); if (tokenType == TokenType.EQ || tokenType == TokenType.EQ_STRICT || tokenType == TokenType.NE || tokenType == TokenType.NE_STRICT binaryNode.lhs().accept(this); add(exp, offsetVisitor.findOffset(binaryNode.lhs()), false); reset(); binaryNode.rhs().accept(this); add(exp, offsetVisitor.findOffset(binaryNode.rhs()), false); reset(); return false; if (binaryNode.rhs() instanceof FunctionNode) { binaryNode.lhs().accept(this); return false; if (binaryNode.isAssignment()) { binaryNode.rhs().accept(this); return false;
private boolean isResultNumber(BinaryNode binaryNode) { boolean bResult = false; TokenType tokenType = binaryNode.tokenType(); Node lhs = binaryNode.lhs(); Node rhs = binaryNode.rhs(); if ((tokenType == TokenType.BIT_OR || tokenType == TokenType.BIT_AND) && ((lhs instanceof LiteralNode && ((LiteralNode) lhs).isNumeric()) || (rhs instanceof LiteralNode && ((LiteralNode) rhs).isNumeric()))) { bResult = true; } else if (tokenType == TokenType.DIV || tokenType == TokenType.MUL || tokenType == TokenType.SUB ){ bResult = true; } else { if (lhs instanceof BinaryNode) { bResult = isResultNumber((BinaryNode) lhs); } else if (rhs instanceof BinaryNode) { bResult = isResultNumber((BinaryNode) rhs); } } return bResult; }
private boolean isKeyAndValueEquals(PropertyNode pNode) { if (pNode.getKey() instanceof IdentNode && pNode.getValue() instanceof IdentNode) { IdentNode key = (IdentNode)pNode.getKey(); IdentNode value = (IdentNode)pNode.getValue(); return key.getName().equals(value.getName()) && key.getStart() == value.getStart(); } if (pNode.getKey() instanceof IdentNode && pNode.getValue() instanceof BinaryNode && ((BinaryNode)pNode.getValue()).tokenType() == TokenType.ASSIGN && ((BinaryNode)pNode.getValue()).lhs() instanceof IdentNode) { IdentNode key = (IdentNode)pNode.getKey(); IdentNode value = (IdentNode)((BinaryNode)pNode.getValue()).lhs(); return key.getName().equals(value.getName()) && key.getStart() == value.getStart(); } return false; }
} else if (init instanceof BinaryNode) { BinaryNode bNode = (BinaryNode) init; if (bNode.isLogical() && ((bNode.rhs() instanceof JoinPredecessorExpression && ((JoinPredecessorExpression) bNode.rhs()).getExpression() instanceof FunctionNode) || (bNode.lhs() instanceof JoinPredecessorExpression && ((JoinPredecessorExpression) bNode.lhs()).getExpression() instanceof FunctionNode))) { } else if (bNode.isAssignment()) { createVariable = false; if (parentFn.getProperty(varNode.getName().getName()) == null) { while (bNode.rhs() instanceof BinaryNode && bNode.rhs().isAssignment()) { bNode = (BinaryNode) bNode.rhs(); if (bNode.rhs() instanceof FunctionNode) { FunctionNode fNode = (FunctionNode) bNode.rhs(); JsObject original = parentFn.getProperty(modelBuilder.getFunctionName(fNode)); if (original != null) {
@Override public Node leaveBinaryNode(BinaryNode binaryNode) { Node lhs = binaryNode.lhs(); Node rhs = binaryNode.rhs(); if (lhs instanceof IdentNode && rhs instanceof BinaryNode) { Node rlhs = ((BinaryNode)rhs).lhs(); if (rlhs instanceof IdentNode) { JsObject origFunction = modelBuilder.getCurrentDeclarationFunction().getProperty(((IdentNode)rlhs).getName()); if (origFunction != null && origFunction.getJSKind().isFunction()) { JsObject refFunction = modelBuilder.getCurrentDeclarationFunction().getProperty(((IdentNode)lhs).getName()); if (refFunction != null && !refFunction.getJSKind().isFunction()) { JsFunctionReference newReference = new JsFunctionReference(refFunction.getParent(), refFunction.getDeclarationName(), (JsFunction)origFunction, true, origFunction.getModifiers()); refFunction.getParent().addProperty(newReference.getName(), newReference); } } } } return super.leaveBinaryNode(binaryNode); }
@Override public Node leaveObjectNode(ObjectNode objectNode) { Node lastVisited = getPreviousFromPath(2); if (lastVisited instanceof BinaryNode) { BinaryNode bNode = (BinaryNode)lastVisited; if (bNode.lhs().equals(objectNode)) { // case of destructuring assignment { a, b} = .... // we dob't create object in the model, but process the property nodes -> skip reseting modelBuilder return super.leaveObjectNode(objectNode); } } modelBuilder.reset(); return super.leaveObjectNode(objectNode); }
@Override public boolean enterAccessNode(AccessNode accessNode) { BinaryNode node = getPath().get(getPath().size() - 1) instanceof BinaryNode ? (BinaryNode)getPath().get(getPath().size() - 1) : null; if (!(node != null && node.tokenType() == TokenType.ASSIGN)) { if (accessNode.getBase() instanceof IdentNode && ModelUtils.THIS.equals(((IdentNode)accessNode.getBase()).getName())) { //NOI18N String iNode = accessNode.getProperty(); JsObject current = modelBuilder.getCurrentDeclarationFunction(); JsObject property = current.getProperty(iNode); if (property == null && current.getParent() != null && (current.getParent().getJSKind() == JsElement.Kind.CONSTRUCTOR || current.getParent().getJSKind() == JsElement.Kind.OBJECT)) { current = current.getParent(); property = current.getProperty(iNode); if (property == null && ModelUtils.PROTOTYPE.equals(current.getName())) { current = current.getParent(); property = current.getProperty(iNode); } } if (property == null && current.getParent() == null) { // probably we are in global space and there is used this property = modelBuilder.getGlobal().getProperty(iNode); } if (property != null && !property.getModifiers().contains(Modifier.PRIVATE)) { // we don't want to add occurrences for cases like var buf = this.buf. See issue #267694 ((JsObjectImpl)property).addOccurrence(new OffsetRange(accessNode.getFinish() - iNode.length(), accessNode.getFinish())); } } } return super.enterAccessNode(accessNode); }
if (bNode.getAssignmentDest() instanceof AccessNode) { AccessNode aNode = (AccessNode)bNode.getAssignmentDest(); List<Identifier> name = getName(aNode, parserResult); if (name != null && ModelUtils.THIS.equals(name.get(0).getName())) {
private boolean isResultString(BinaryNode binaryNode) { boolean bResult = false; TokenType tokenType = binaryNode.tokenType(); Node lhs = binaryNode.lhs(); Node rhs = binaryNode.rhs(); if (tokenType == TokenType.ADD && ((lhs instanceof LiteralNode && ((LiteralNode) lhs).isString()) || (rhs instanceof LiteralNode && ((LiteralNode) rhs).isString()))) { bResult = true; } else { if (lhs instanceof JoinPredecessorExpression) { lhs = ((JoinPredecessorExpression)lhs).getExpression(); } if (rhs instanceof JoinPredecessorExpression) { rhs = ((JoinPredecessorExpression)rhs).getExpression(); } if (lhs instanceof BinaryNode) { bResult = isResultString((BinaryNode) lhs); } else if (rhs instanceof BinaryNode) { bResult = isResultString((BinaryNode) rhs); } } return bResult; }
if (getPreviousFromPath(pathIndex + 3) instanceof BinaryNode) { BinaryNode bNode = (BinaryNode) getPreviousFromPath(pathIndex + 3); if (bNode.tokenType() == TokenType.ASSIGN) { if (bNode.lhs() instanceof AccessNode) { List<Identifier> identifier = getName((AccessNode) bNode.lhs(), parserResult); if (identifier != null) { if (!identifier.isEmpty() && ModelUtils.THIS.equals(identifier.get(0).getName())) { } else if (bNode.lhs() instanceof IdentNode) { name = ((IdentNode) bNode.lhs()).getName();
while (bNode.rhs() instanceof BinaryNode ) { bNode = (BinaryNode)bNode.rhs(); if (bNode.rhs() instanceof FunctionNode) { rNode = (FunctionNode) bNode.rhs(); List<Identifier> name = getNodeName(bNode.lhs(), parserResult); if (name != null && !name.isEmpty()) { boolean isPriviliged = name.get(0).getName().equals(ModelUtils.THIS);
private static List<Identifier> getName(BinaryNode binaryNode, ParserResult parserResult) { List<Identifier> name = new ArrayList(); Node lhs = binaryNode.lhs(); if (lhs instanceof AccessNode) { name = getName((AccessNode)lhs, parserResult);
@Override public boolean enterBinaryNode(BinaryNode binaryNode) { Node lhs = binaryNode.lhs(); Node rhs = binaryNode.rhs(); if (lhs instanceof LiteralNode.ArrayLiteralNode && binaryNode.tokenType() == TokenType.ASSIGN) { } else if (lhs instanceof ObjectNode && binaryNode.tokenType() == TokenType.ASSIGN) { } else if (lPropertyNode.getValue() instanceof BinaryNode) { BinaryNode bNode = (BinaryNode)lPropertyNode.getValue(); if (bNode.tokenType() == TokenType.ASSIGN && bNode.lhs() instanceof IdentNode) { variableName = ((IdentNode)bNode.lhs()).getName(); processBinaryNode(lhs, rhs, binaryNode.tokenType());
&& ((BinaryNode)lastVisited).tokenType() != TokenType.ASSIGN) { pathIndex++; lastVisited = getPath().get(pathSize - pathIndex); } else if (lastVisited instanceof BinaryNode) { BinaryNode binNode = (BinaryNode) lastVisited; if (binNode.lhs() instanceof IndexNode) { Node index = ((IndexNode)binNode.lhs()).getIndex(); if (!(index instanceof LiteralNode && ((LiteralNode)index).isString())) { treatAsAnonymous = true; if ((binNode.lhs() instanceof IdentNode) || (binNode.lhs() instanceof AccessNode && ((AccessNode) binNode.lhs()).getBase() instanceof IdentNode && ((IdentNode) ((AccessNode) binNode.lhs()).getBase()).getName().equals(ModelUtils.THIS))) { //NOI18N if (lastVisited instanceof ExpressionStatement && !fqName.get(0).getName().equals(ModelUtils.THIS)) { //NOI18N if (!(binNode.lhs() instanceof IdentNode)) { parent = resolveThis(modelBuilder.getCurrentObject());
if (node instanceof Block) { Block block = (Block)node; if (block.isParameterBlock() && oNode != null && bNode != null && bNode.lhs().equals(oNode) ) {
|| (previousVisited instanceof BinaryNode && ((BinaryNode)previousVisited).tokenType() == TokenType.COMMARIGHT)) { JsObjectImpl objectScope = ModelElementFactory.createAnonymousObject(parserResult, objectNode, modelBuilder); modelBuilder.setCurrentObject(objectScope); if (bNode.lhs().equals(objectNode)) { } else if (bNode.lhs() instanceof ObjectNode && bNode.rhs().equals(objectNode)) { && ((BinaryNode)lastVisited).tokenType() != TokenType.ASSIGN) { pathIndex++; lastVisited = getPath().get(pathSize - pathIndex); } else if (lastVisited instanceof BinaryNode) { BinaryNode binNode = (BinaryNode) lastVisited; Node binLhs = binNode.lhs(); if (binLhs instanceof IndexNode) { Node index = ((IndexNode)binLhs).getIndex();
if (lastNode instanceof BinaryNode) { BinaryNode bNode = (BinaryNode)lastNode; if (bNode.lhs().equals(accessNode)) { object = (JsObjectImpl) variable; if (lastVisited instanceof BinaryNode) { BinaryNode bNode = (BinaryNode)lastVisited; onLeftSite = bNode.tokenType() == TokenType.ASSIGN && bNode.lhs().equals(accessNode);