/** * 中断接受节点 * * @param node : 函数调用 */ public void interruptAcceptNodeHandle(MethodInvocation node) { int lineNumber = compilationUnit.getLineNumber(node.getStartPosition()); Node interruptedNode = new Node(filePath, lineNumber); String threadKey; Expression expression = node.getExpression(); ITypeBinding iTypeBinding = castHelper.getResolveTypeBinding(expression); if (expression == null || iTypeBinding == null) { System.out.println(filePath); System.out.println(compilationUnit.getLineNumber(node.getStartPosition())); System.out.println("interrupt iTypeBinding error!"); return; } // 普通变量 if (expression instanceof SimpleName && ((SimpleName) expression).resolveBinding() != null) { SimpleName simpleName = (SimpleName) expression; if (castHelper.getDecNode(simpleName) == null) { return; } int decLineNumber = compilationUnit.getLineNumber(castHelper.getDecNode(simpleName).getStartPosition()); String varKey = filePath + "_" + decLineNumber + "_" + iTypeBinding.getName() + "_" + simpleName.getIdentifier(); System.out.println(varKey); if (threadVarHashMap.containsKey(varKey)) { threadKey = threadVarHashMap.get(varKey).getThreadInfoKey(); if (threadInfo.get(threadKey).getInterruptNodes() != null) { threadInfo.get(threadKey).getInterruptNodes().add(interruptedNode); } } else { System.out.println("ERROR: didn't contains the varKey"); } } // 其它调用 else if (((SimpleName) expression).resolveBinding() != null) { threadKey = iTypeBinding.getBinaryName(); if (threadInfo.get(threadKey).getInterruptNodes() != null) { threadInfo.get(threadKey).getInterruptNodes().add(interruptedNode); } } }
/** * 中断通知节点 * * @param node :函数调用 * @param threadInterruptNode :中断节点类 */ public void interruptNotifyNodeHandle( MethodInvocation node, ThreadInterruptNode threadInterruptNode) { String threadKey; Expression expression = node.getExpression(); ITypeBinding iTypeBinding = castHelper.getResolveTypeBinding(expression); if (expression == null || iTypeBinding == null) { System.out.println(filePath); System.out.println(compilationUnit.getLineNumber(node.getStartPosition())); System.out.println("interrupt iTypeBinding error!"); return; } // 普通变量,从变量集中获取线程key if (expression instanceof SimpleName && ((SimpleName) expression).resolveBinding() != null) { SimpleName simpleName = (SimpleName) expression; int lineNumber = compilationUnit.getLineNumber(castHelper.getDecNode(simpleName).getStartPosition()); String varKey = filePath + "_" + lineNumber + "_" + iTypeBinding.getName() + "_" + simpleName.getIdentifier(); System.out.println(varKey); if (threadVarHashMap.containsKey(varKey)) { threadKey = threadVarHashMap.get(varKey).getThreadInfoKey(); threadInterruptNode.getThreadKeyList().add(threadKey); // 添加至中断通知节点集合 threadInterruptNodes.add(threadInterruptNode); } else { System.out.println("ERROR: didn't contains the varKey"); } } // 其它调用(函数返回值等):直接从返回值类型推断具体线程key else { threadKey = iTypeBinding.getBinaryName(); threadInterruptNode.getThreadKeyList().add(threadKey); } }