コード例 #1
0
 private void extractVariableDeclarationFragments(
     List<VariableDeclarationFragment> fragments, List<Statement> stmtList) {
   for (int i = 0; i < fragments.size(); i++) {
     VariableDeclarationFragment frag = fragments.get(i);
     Expression init = frag.getInitializer();
     if (init == null) {
       continue;
     }
     newExpression(init);
     init.accept(this);
     List<VariableAccess> toExtract = getUnsequencedAccesses();
     if (!toExtract.isEmpty()) {
       if (i > 0) {
         // Extract all fragments before the current one to preserve ordering.
         VariableDeclarationStatement newDecl =
             new VariableDeclarationStatement(fragments.get(0).copy());
         for (int j = 1; j < i; j++) {
           newDecl.getFragments().add(fragments.get(j).copy());
         }
         stmtList.add(newDecl);
         fragments.subList(0, i).clear();
       }
       extractOrderedAccesses(stmtList, currentTopNode, toExtract);
       i = 0;
     }
   }
 }
コード例 #2
0
 @Override
 public boolean visit(VariableDeclarationStatement node) {
   extractVariableDeclarationFragments(
       node.getFragments(), TreeUtil.asStatementList(node).subList(0, 0));
   return false;
 }