private static boolean isLiveInMethodEntry(Symbol privateFieldSymbol, MethodTree methodTree) { CFG cfg = CFG.build(methodTree); LiveVariables liveVariables = LiveVariables.analyzeWithFields(cfg); return liveVariables.getIn(cfg.entryBlock()).contains(privateFieldSymbol); }
@Override public void visitNode(Tree tree) { SwitchStatementTree switchStatementTree = (SwitchStatementTree) tree; List<CaseGroupTree> caseGroupTrees = switchStatementTree.cases(); CFG cfg = CFG.buildCFG(Collections.singletonList(tree), true); Set<CFG.Block> switchSuccessors = cfg.entryBlock().successors(); Map<CFG.Block, CaseGroupTree> cfgBlockToCaseGroupMap = createMapping(switchSuccessors, caseGroupTrees); switchSuccessors.stream() .filter(cfgBlockToCaseGroupMap.keySet()::contains) .flatMap(cfgBlock -> getForbiddenCaseGroupPredecessors(cfgBlock, cfgBlockToCaseGroupMap)) .map(CaseGroupTree::labels) .map(caseGroupLabels -> caseGroupLabels.get(caseGroupLabels.size() - 1)) .forEach(label -> reportIssue(label, "End this switch case with an unconditional break, return or throw statement.")); }
@Override public void visitNode(Tree tree) { SwitchStatementTree switchStatementTree = (SwitchStatementTree) tree; List<CaseGroupTree> caseGroupTrees = switchStatementTree.cases(); CFG cfg = CFG.buildCFG(Collections.singletonList(tree), true); Set<CFG.Block> switchSuccessors = cfg.entryBlock().successors(); Map<CFG.Block, CaseGroupTree> cfgBlockToCaseGroupMap = createMapping(switchSuccessors, caseGroupTrees); switchSuccessors.stream() .filter(cfgBlockToCaseGroupMap.keySet()::contains) .flatMap(cfgBlock -> getForbiddenCaseGroupPredecessors(cfgBlock, cfgBlockToCaseGroupMap)) .map(CaseGroupTree::labels) .map(caseGroupLabels -> caseGroupLabels.get(caseGroupLabels.size() - 1)) .forEach(label -> reportIssue(label, "End this switch case with an unconditional break, return or throw statement.")); }
private static boolean isLiveInMethodEntry(Symbol privateFieldSymbol, MethodTree methodTree) { CFG cfg = CFG.build(methodTree); LiveVariables liveVariables = LiveVariables.analyzeWithFields(cfg); return liveVariables.getIn(cfg.entryBlock()).contains(privateFieldSymbol); }
@Override public void visitMethod(MethodTree tree) { BlockTree block = tree.block(); if(block == null) { return; } CFG cfg = CFG.build(tree); LiveVariables analyze = LiveVariables.analyze(cfg); Set<Symbol> live = analyze.getIn(cfg.entryBlock()); for (VariableTree parameterTree : tree.parameters()) { if(!live.contains(parameterTree.symbol())) { variables.add(parameterTree.symbol()); } } super.visitMethod(tree); for (VariableTree parameterTree : tree.parameters()) { if(!live.contains(parameterTree.symbol())) { variables.remove(parameterTree.symbol()); } } }
@Override public void visitMethod(MethodTree tree) { BlockTree block = tree.block(); if(block == null) { return; } CFG cfg = CFG.build(tree); LiveVariables analyze = LiveVariables.analyze(cfg); Set<Symbol> live = analyze.getIn(cfg.entryBlock()); for (VariableTree parameterTree : tree.parameters()) { if(!live.contains(parameterTree.symbol())) { variables.add(parameterTree.symbol()); } } super.visitMethod(tree); for (VariableTree parameterTree : tree.parameters()) { if(!live.contains(parameterTree.symbol())) { variables.remove(parameterTree.symbol()); } } }
@Override public void visitCatch(CatchTree tree) { CFG cfg = CFG.buildCFG(tree.block().body(), true); Symbol var = tree.parameter().symbol(); boolean liveVar = true; if(var.owner().isMethodSymbol()) { cfg.setMethodSymbol((Symbol.MethodSymbol) var.owner()); LiveVariables analyze = LiveVariables.analyze(cfg); Set<Symbol> live = analyze.getIn(cfg.entryBlock()); liveVar = live.contains(var); } if(!liveVar) { variables.add(var); } super.visitCatch(tree); if(!liveVar) { variables.remove(var); } }
@Override public void visitCatch(CatchTree tree) { CFG cfg = CFG.buildCFG(tree.block().body(), true); Symbol var = tree.parameter().symbol(); boolean liveVar = true; if(var.owner().isMethodSymbol()) { cfg.setMethodSymbol((Symbol.MethodSymbol) var.owner()); LiveVariables analyze = LiveVariables.analyze(cfg); Set<Symbol> live = analyze.getIn(cfg.entryBlock()); liveVar = live.contains(var); } if(!liveVar) { variables.add(var); } super.visitCatch(tree); if(!liveVar) { variables.remove(var); } }
steps = 0; for (ProgramState startingState : startingStates(tree, programState)) { enqueue(new ProgramPoint(cfg.entryBlock()), startingState);
steps = 0; for (ProgramState startingState : startingStates(tree, programState)) { enqueue(new ProgramPoint(cfg.entryBlock()), startingState);