diff --git a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java index b11dd59..04fe38f 100644 --- a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java +++ b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java @@ -2,9 +2,12 @@ import java.io.File; import java.util.ArrayList; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Objects; import org.eclipse.core.filebuffers.FileBuffers; import org.eclipse.core.filebuffers.ITextFileBuffer; @@ -283,21 +286,22 @@ startRegister(); } if (node.getLeftHandSide().toString().equals("result")) { - var right = node.getRightHandSide(); - - stopRegister(""); + MethodInvocation right = (MethodInvocation) node.getRightHandSide(); + String resourceName =((MethodInvocation) ((MethodInvocation) right.getExpression()).getExpression()).arguments().get(0).toString(); + stopRegister(resourceName); } return super.visit(node); } private void startRegister() { isRegistering[0] = true; + statements.clear(); } private void stopRegister(String resourceName) { statements.add(statement); - invocations.put(resourceName,statements); + invocations.put(resourceName, List.copyOf(statements)); isRegistering[0] = false; } }); @@ -307,9 +311,51 @@ } System.out.println(invocations); + //���\�b�h�̌Ăяo���Q��2�ˆȏ�ł���, + //invocations����Ή����\�[�X�ւ̃��\�b�h�Ăяo���Q��, + //invocations�̐擪�ɂ��郁�\�b�h�Ăяo���Q����v���邩�𔻒� + Iterator>> invocationsIterator = invocations.entrySet().iterator(); + var g =invocations.get(resourceName); + var i = (invocationsIterator.next()).getKey().equals(resourceName); + if(invocations.size() > 1 + && i ){ + + var entityStatement = ""; + var formStatement = ""; + var resultStatement = ""; + for(Statement st : (List)invocationsIterator.next().getValue()) { + ASTNode[] n = new ASTNode[1]; + st.accept(new ASTVisitor () { + @Override + public boolean visit(Assignment node) { + if (node.getLeftHandSide().toString().equals("form")) { + n[0] = node; + addDecStatement(node, "Form "); + } + if (node.getLeftHandSide().toString().equals("entity")) { + n[0] = node; + addDecStatement(node, "Entity
"); + } + if (node.getLeftHandSide().toString().equals("result")) { + MethodInvocation right = (MethodInvocation) node.getRightHandSide(); + n[0] = node; + addDecStatement(node, "String "); + } + return super.visit(node); + } + public void addDecStatement(Assignment node, String typeName) { + // addStatement(astRewrite, srcUnit, node, typeName, Assignment ); + addStatementBefore(astRewrite, srcUnit, md.getBody(), node.getParent(), typeName, Block.STATEMENTS_PROPERTY ); + } + }); + + } + } + for(Statement st : invocations.get(resourceName)) { deleteASTNode(astRewrite, srcUnit ,st ); } + } } @@ -408,7 +454,7 @@ }else { parsedKey += tmpValue + ".entrySet().iterator().next().getKey()"; } - // parseInt���܂��ł��ĂȂ� + String str = "new AbstractMap.SimpleEntry<>(" + parsedKey +", " + tmpValue + ".entrySet().iterator().next().getValue())"; return str; @@ -460,6 +506,19 @@ TextEditGroup dstEditGroup = new TextEditGroup("new class edit group"); dstUnitRewriteList.insertFirst(statement, dstEditGroup); } + + private void addStatementBefore(ASTRewrite astRewrite, CompilationUnit cu, ASTNode astNode, ASTNode nextNode, String statementCode, + ChildListPropertyDescriptor childListPropertyDescriptor) { + ListRewrite dstUnitRewriteList = astRewrite.getListRewrite(astNode, childListPropertyDescriptor); + PackageDeclaration dstPackageDeclaration = cu.getPackage(); + + Statement statement = (Statement) astRewrite.createStringPlaceholder(statementCode, + ASTNode.VARIABLE_DECLARATION_STATEMENT); + + astRewrite.set(cu, CompilationUnit.PACKAGE_PROPERTY, dstPackageDeclaration, null); + TextEditGroup dstEditGroup = new TextEditGroup("new class edit group"); + dstUnitRewriteList.insertBefore(statement, nextNode, dstEditGroup); + } private void deleteASTNode(ASTRewrite astRewrite, CompilationUnit cu, ASTNode astNode) { TextEditGroup dstEditGroup = new TextEditGroup("new class edit group");