private void addDuplicatedMethodError( String message, IOpenMethod method, IOpenMethod existedMethod) { ISyntaxNode newMethodSyntaxNode = method.getInfo().getSyntaxNode(); if (newMethodSyntaxNode instanceof TableSyntaxNode) { SyntaxNodeException error = SyntaxNodeExceptionUtils.createError(message, newMethodSyntaxNode); ((TableSyntaxNode) newMethodSyntaxNode).addError(error); try { TableSyntaxNode existedMethodSyntaxNode = (TableSyntaxNode) existedMethod.getInfo().getSyntaxNode(); if (existedMethodSyntaxNode != null) { existedMethodSyntaxNode.addError( SyntaxNodeExceptionUtils.createError(message, existedMethodSyntaxNode)); } } catch (Exception ex) { log.warn( "Cannot get a syntax node for the method: {}", MethodUtil.printMethod(existedMethod, new StringBuilder()), ex); } addError(error); } else { addError(new DuplicatedMethodException(message, method)); } }
private IBoundNode cantFindMethodError( ISyntaxNode node, IBindingContext bindingContext, String methodName, IOpenClass[] parameterTypes) { String message = String.format("Method '%s' not found", MethodUtil.printMethod(methodName, parameterTypes)); BindHelper.processError(message, node, bindingContext, false); return new ErrorBoundNode(node); }
@Override public IBoundNode bindTarget(ISyntaxNode node, IBindingContext bindingContext, IBoundNode target) throws Exception { int childrenCount = node.getNumberOfChildren(); if (childrenCount < 1) { BindHelper.processError("New node should have at least one subnode", node, bindingContext); return new ErrorBoundNode(node); } ISyntaxNode lastNode = node.getChild(childrenCount - 1); String methodName = ((IdentifierNode) lastNode).getIdentifier(); IBoundNode[] children = bindChildren(node, bindingContext, 0, childrenCount - 1); IOpenClass[] types = getTypes(children); IMethodCaller methodCaller = MethodSearch.getMethodCaller(methodName, types, bindingContext, target.getType()); if (methodCaller == null) { StringBuilder buf = new StringBuilder("Method "); MethodUtil.printMethod(methodName, types, buf); buf.append(" not found in '").append(target.getType().getName()).append("'"); BindHelper.processError(buf.toString(), node, bindingContext, false); return new ErrorBoundNode(node); } if (target.isStaticTarget() != methodCaller.getMethod().isStatic()) { if (methodCaller.getMethod().isStatic()) { BindHelper.processWarn( "Access of a static method from non-static object", node, bindingContext); } else { BindHelper.processError( "Access of a non-static method from a static object", node, bindingContext); return new ErrorBoundNode(node); } } MethodBoundNode result = new MethodBoundNode(node, children, methodCaller, target); result.setTargetNode(target); return result; }