diff --git a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java index f368601..ddc6246 100644 --- a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java +++ b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java @@ -95,9 +95,17 @@ import org.eclipse.text.edits.TextEdit; import org.eclipse.text.edits.TextEditGroup; import org.eclipse.text.edits.UndoEdit; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.editors.text.FileDocumentProvider; import org.eclipse.ui.editors.text.TextEditor; +import org.eclipse.ui.ide.IDE; import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IDocumentProviderExtension; @@ -159,6 +167,7 @@ } else { changePull2Push(pm); } + return result; } @@ -246,13 +255,40 @@ private void applyRewrite(CompilationUnit unit, ASTRewrite unitRewrite, IProgressMonitor pm) throws Exception { IPath path = unit.getJavaElement().getPath(); + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IFile file = workspaceRoot.getFile(path); +// if(isOpened(file)) { +// IWorkbench workbench = PlatformUI.getWorkbench(); +// IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); +// IWorkbenchPage page = window.getActivePage(); +// IEditorPart editor = IDE.openEditor(page, file); +// } ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); bufferManager.connect(path, LocationKind.IFILE, pm); ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path, LocationKind.IFILE); IDocument document = textFileBuffer.getDocument(); TextEdit edit = unitRewrite.rewriteAST(document, null); UndoEdit undo = edit.apply(document); - textFileBuffer.commit(pm /* ProgressMonitor */, true/* Overwrite */); + textFileBuffer.commit(null /* ProgressMonitor */, true/* Overwrite */); + + } + + private boolean isOpened(IFile targetFile) { + IEditorInput input = new FileEditorInput(targetFile); + IWorkbench workbench = PlatformUI.getWorkbench(); + IWorkbenchWindow[] windows = workbench.getWorkbenchWindows(); + for (int i = 0; i < windows.length; i++) { + IWorkbenchPage[] pages = windows[i].getPages(); + for (int j = 0; j < pages.length; j++) { + IEditorPart editor = pages[j].findEditor(input); + if (editor != null) { + // �G�f�B�^�ŊJ����Ă��� + return true; + } + } + } + // �G�f�B�^�ŊJ����Ă��Ȃ� + return false; } private void deletePutMethodInvocation(ASTRewrite astRewrite, CompilationUnit srcUnit, String resourceName) { @@ -403,7 +439,7 @@ tmp = assignedValue + "_json"; result += "List<" + convertType((Type) ptype.typeArguments().get(0)) + "> "; - result += tmp + " = client.target(\"http://localhost:8080\").path(\"/" + path + "\").request().get(" + result += tmp + " = client.target(\"http://localhost:8080\").path(this."+path+").request().get(" + simpleType + ".class);" + System.getProperty("line.separator"); result += "List<" + ptype.typeArguments().get(0) + "> " + assignedValue + " = new ArrayList<>();" @@ -415,7 +451,7 @@ simpleType = "HashMap"; tmp = assignedValue + "_json"; result += convertType((Type) ptype) + " "; - result += tmp + " = client.target(\"http://localhost:8080\").path(\"/" + path + "\").request().get(" + result += tmp + " = client.target(\"http://localhost:8080\").path(this."+path+").request().get(" + simpleType + ".class);" + System.getProperty("line.separator"); result += (Type) ptype + " " + assignedValue + " = new AbstractMap.SimpleEntry<>(" + tmp @@ -514,19 +550,20 @@ var ptype = (ParameterizedType) srcType; if (ptype.getType().toString().equals("List")) { var typeArg = (Type) ptype.typeArguments().get(0); - code += "for ("+typeArg+" i: this.value) {" + System.getProperty("line.separator"); - code += "\t form.param(\"" + srcValue +"\", new ObjectMapper().writeValueAsString(i);"+ System.getProperty("line.separator"); + code += "for (" + typeArg + " i: this.value) {" + System.getProperty("line.separator"); + code += "\t form.param(\"" + srcValue + "\", new ObjectMapper().writeValueAsString(i);" + + System.getProperty("line.separator"); code += "}" + System.getProperty("line.separator"); } if (ptype.getType().toString().equals("Map.Entry")) { code += "form.param(\"" + srcValue + "\", new ObjectMapper().writeValueAsString(this.value));" + System.getProperty("line.separator"); } - }else { + } else { code += "form.param(\"" + srcValue + "\", new ObjectMapper().writeValueAsString(this.value));" + System.getProperty("line.separator"); } - + if (invocations.size() == 0) code += "Entity "; code += "entity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED);" @@ -553,7 +590,7 @@ // Shipping �N���X�ɏo�Ɏw���̓��e��ۑ����邽�߂̃t�B�[���h Item value ��lj�����D Type dstType = searchMethodDeclaration(dstUnit, "Getter").getReturnType2(); - + String stateCode = "@State" + System.getProperty("line.separator") + dstType.toString() + " value;"; addStatement(dstUnitRewrite, dstUnit, dstDec[0], stateCode); // Shipping �N���X�� void updateHandling(ItemHandling handling) ���\�b�h��lj�����D @@ -625,18 +662,6 @@ } result += "}" + System.getProperty("line.separator"); - /* - * @PUT public void updateHandling(@FormParam("handling") String handling_json) - * throws JsonProcessingException { Map.Entry> handling; { Map> i = new - * ObjectMapper().readValue(handling_json, HashMap.class); handling = new - * AbstractMap.SimpleEntry<>(i.entrySet().iterator().next().getKey(), new - * AbstractMap.SimpleEntry<>(Integer.parseInt(i.entrySet().iterator().next(). - * getValue().entrySet().iterator().next().getKey()), - * i.entrySet().iterator().next().getValue().entrySet().iterator().next(). - * getValue())); } this.value = new AbstractMap.SimpleEntry<>(handling.getKey(), - * handling.getValue().getKey()); } - */ return result; } @@ -753,7 +778,7 @@ TextEdit edit = rewrite.rewriteAST(document, null); edit.apply(document); textFileBuffer.commit(pm /* ProgressMonitor */, true/* Overwrite */); - + IDocumentProvider provider; } catch (Exception e) { e.printStackTrace(); }