diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..2869279 --- /dev/null +++ b/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..eab3feb --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# デフォルトの無視対象ファイル +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..15cec4b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f94b6f8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..b703fb3 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + org.ntlab.pushPullRefactoring + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..88e0c67 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: PushPullRefactoring +Bundle-SymbolicName: org.ntlab.pushPullRefactoring;singleton:=true +Bundle-Version: 1.0.0.qualifier +Automatic-Module-Name: org.ntlab.pushPullRefactoring +Require-Bundle: org.eclipse.ltk.core.refactoring, + org.eclipse.jdt.core;bundle-version="3.18.0", + org.eclipse.jdt.core.manipulation;bundle-version="1.11.200", + org.eclipse.core.runtime;bundle-version="3.15.300", + org.eclipse.core.commands;bundle-version="3.9.400", + org.eclipse.jdt.ui;bundle-version="3.18.0", + org.eclipse.jface;bundle-version="3.16.0", + org.eclipse.ui.workbench;bundle-version="3.115.0", + org.eclipse.core.resources;bundle-version="3.13.400" diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..cf1db2e --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/org/ diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..e9863e2 --- /dev/null +++ b/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/org.ntlab.pushPullRefactoring.iml b/org.ntlab.pushPullRefactoring.iml new file mode 100644 index 0000000..14a9cb0 --- /dev/null +++ b/org.ntlab.pushPullRefactoring.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..f70dc39 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/org/ntlab/pushPullRefactoring/PushPullDescriptor.java b/src/org/ntlab/pushPullRefactoring/PushPullDescriptor.java new file mode 100644 index 0000000..dcb263e --- /dev/null +++ b/src/org/ntlab/pushPullRefactoring/PushPullDescriptor.java @@ -0,0 +1,12 @@ +package org.ntlab.pushPullRefactoring; + +import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor; + +public class PushPullDescriptor extends JavaRefactoringDescriptor { + + protected PushPullDescriptor() { + super(PushPullRefactoring.ID); + } + + +} diff --git a/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java new file mode 100644 index 0000000..bb3f21d --- /dev/null +++ b/src/org/ntlab/pushPullRefactoring/PushPullProcessor.java @@ -0,0 +1,154 @@ +package org.ntlab.pushPullRefactoring; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.search.IJavaSearchConstants; +import org.eclipse.jdt.core.search.IJavaSearchScope; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.core.search.SearchMatch; +import org.eclipse.jdt.core.search.SearchParticipant; +import org.eclipse.jdt.core.search.SearchPattern; +import org.eclipse.jdt.core.search.SearchRequestor; +import org.eclipse.jdt.internal.core.SourceType; +import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; +import org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationRefactoringChange; +import org.eclipse.jdt.internal.corext.refactoring.changes.RenameCompilationUnitChange; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; +import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant; +import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor; +import org.eclipse.ltk.core.refactoring.participants.SharableParticipants; + +public class PushPullProcessor extends RefactoringProcessor { + private PushPullDescriptor descriptor = null; + public PushPullProcessor(PushPullDescriptor descriptor) { + this.descriptor = descriptor; + } + + @Override + public Object[] getElements() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getIdentifier() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getProcessorName() { + // TODO Auto-generated method stub + return PushPullRefactoring.NAME; + } + + @Override + public boolean isApplicable() throws CoreException { + // TODO Auto-generated method stub + return false; + } + + @Override + public RefactoringStatus checkInitialConditions(IProgressMonitor pm) + throws CoreException, OperationCanceledException { + // TODO Auto-generated method stub + return null; + } + + @Override + public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) + throws CoreException, OperationCanceledException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { + // TODO Auto-generated method stub + DynamicValidationRefactoringChange result = new DynamicValidationRefactoringChange(descriptor, PushPullRefactoring.NAME); + ICompilationUnit[] icus = new ICompilationUnit[1]; +// IResourceVisitor visitor = new IResourceVisitor() { +// @Override +// public boolean visit(IResource resource) throws CoreException { +// // TODO Auto-generated method stub +// if (resource.getType() == IResource.FILE) { +// IJavaElement je = JavaCore.create(resource); +// if (je != null && je.getElementType() == +// IJavaElement.COMPILATION_UNIT) { +// ICompilationUnit icu = (ICompilationUnit)je; +// System.out.println("name:" + icu.getElementName()); +// if (icu.getElementName().equals("A")) { +// icus[0] = icu; +// } +// } +// } +// return false; +// } +// }; + + IWorkspace w = ResourcesPlugin.getWorkspace(); + //w.getRoot().accept(visitor, IContainer.DEPTH_INFINITE, false); + + SearchPattern pattern = createSearchPattern(); + SearchParticipant[] participants = { SearchEngine.getDefaultSearchParticipant() }; + + IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); +// IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject }); + SearchRequestor requestor = new SearchRequestor() { + @Override + public void acceptSearchMatch(SearchMatch match) throws CoreException { + IJavaElement element = (IJavaElement) match.getElement(); + + System.out.println(element.getElementType()); + ICompilationUnit icu = ((SourceType) element).getCompilationUnit(); + System.out.println("name:" + icu.getElementName()); + if (icu.getElementName().equals("A.java")) { + icus[0] = icu; + } + + System.out.printf("%s %d,%d\n", element.getElementName(), match.getOffset(), match.getLength()); + } + }; + + try { + new SearchEngine().search(pattern, participants, scope, requestor, new NullProgressMonitor()); + } catch (CoreException e) { + e.printStackTrace(); + } + if (icus[0] != null) { + result.add(new RenameCompilationUnitChange(icus[0], "A2.java")); + } + + return result; + } + private SearchPattern createSearchPattern() { + + String pattern = "A"; + int searchFor = IJavaSearchConstants.TYPE; + + int limitTo = IJavaSearchConstants.DECLARATIONS; + int matchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE | SearchPattern.R_ERASURE_MATCH; + return SearchPattern.createPattern(pattern, searchFor, limitTo, matchRule); + } + @Override + public RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants) + throws CoreException { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/org/ntlab/pushPullRefactoring/PushPullRefactoring.java b/src/org/ntlab/pushPullRefactoring/PushPullRefactoring.java new file mode 100644 index 0000000..319cdfb --- /dev/null +++ b/src/org/ntlab/pushPullRefactoring/PushPullRefactoring.java @@ -0,0 +1,13 @@ +package org.ntlab.pushPullRefactoring; + +import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring; + +public class PushPullRefactoring extends ProcessorBasedRefactoring { + public static final String ID = "org.ntlab.pushPullRefactoring"; + public static final String NAME = "PushPull Refactoring"; + + public PushPullRefactoring(PushPullProcessor pushPullProcessor) { + super(pushPullProcessor); + + } +} diff --git a/src/org/ntlab/pushPullRefactoring/PushPullRefactoringContribution.java b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringContribution.java new file mode 100644 index 0000000..f41d0ef --- /dev/null +++ b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringContribution.java @@ -0,0 +1,40 @@ +package org.ntlab.pushPullRefactoring; + +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringContribution; +import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor; +import org.eclipse.ltk.core.refactoring.Refactoring; +import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; + +public class PushPullRefactoringContribution extends JavaRefactoringContribution { + + @Override + public RefactoringDescriptor createDescriptor(String id, String project, String description, String comment, + Map arguments, int flags) throws IllegalArgumentException { + + return new PushPullDescriptor(); + } + @Override + public RefactoringDescriptor createDescriptor() throws IllegalArgumentException { + + return new PushPullDescriptor(); + } + + + @Override + public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) + throws CoreException { + if (!(descriptor instanceof PushPullDescriptor)) { + status.addFatalError("Unknown Descriptor"); + return null; + } + + + return new PushPullRefactoring(new PushPullProcessor((PushPullDescriptor) descriptor)); + } + + +} diff --git a/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java new file mode 100644 index 0000000..f129ac5 --- /dev/null +++ b/src/org/ntlab/pushPullRefactoring/PushPullRefactoringHandler.java @@ -0,0 +1,72 @@ +package org.ntlab.pushPullRefactoring; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper; +import org.eclipse.ltk.core.refactoring.RefactoringCore; +import org.eclipse.ltk.core.refactoring.RefactoringStatus; +import org.eclipse.ui.handlers.HandlerUtil; + +public class PushPullRefactoringHandler implements IHandler { + + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + // TODO Auto-generated method stub + + } + + @Override + public void dispose() { + // TODO Auto-generated method stub + + } + + /** + * ���j���[�ŁuPushPullRefactoring...�v���������ꂽ�Ƃ��Ɏ��s + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + // TODO Auto-generated method stub + System.out.println("Hello Push-Pull Refactoring!!"); + PushPullRefactoringContribution contribution = (PushPullRefactoringContribution)RefactoringCore.getRefactoringContribution(PushPullRefactoring.ID); + PushPullDescriptor descriptor = (PushPullDescriptor) contribution.createDescriptor(); + try { + PushPullRefactoring refactoring = (PushPullRefactoring) contribution.createRefactoring(descriptor, null); + + RefactoringExecutionHelper helper= new RefactoringExecutionHelper(refactoring, + RefactoringCore.getConditionCheckingFailedSeverity(), + RefactoringStatus.FATAL, + HandlerUtil.getActiveShell(event), + HandlerUtil.getActiveWorkbenchWindow(event)); + helper.perform(true, true); + } catch (CoreException | InvocationTargetException | InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + @Override + public boolean isEnabled() { + System.out.println(this.getClass().getSimpleName() + "#" + "isEnabled()"); + return true; + } + + @Override + public boolean isHandled() { + System.out.println(this.getClass().getSimpleName() + "#" + "isHandled()"); + return true; + } + + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + // TODO Auto-generated method stub + + } + +}