@Override protected RefactoringStatus verifyDestination(Object selected) throws JavaModelException { JavaMoveProcessor processor = getJavaMoveProcessor(); final RefactoringStatus refactoringStatus = processor.setDestination(ReorgDestinationFactory.createDestination(selected)); updateUIStatus(); fDestination = selected; return refactoringStatus; }
/** Makes the fix */ public boolean fix() { IResource source = marker.getResource(); IJavaElement javaElem = JavaCore.create(source); ICompilationUnit compUnit = (ICompilationUnit) javaElem; IProgressMonitor pm = new NullProgressMonitor(); try { // create move policy and processor for the compilation unit IMovePolicy movePolicy = ReorgPolicyFactory.createMovePolicy( new IResource[] {compUnit.getResource()}, new IJavaElement[] {compUnit}); JavaMoveProcessor processor = new JavaMoveProcessor(movePolicy); if (newSource == null) return false; processor.setDestination(ReorgDestinationFactory.createDestination(newSource)); // the refactoring object Refactoring refactoring = new ProcessorBasedRefactoring(processor); // set a refactoring wizard RefactoringWizard wizard = new ReorgMoveWizard(processor, refactoring); Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); wizard.setContainer(new RefactoringWizardDialog(activeShell, wizard)); // set reorg queries (no idea what it is used for, but doesn't work without it) processor.setCreateTargetQueries(new CreateTargetQueries(wizard)); processor.setReorgQueries(new ReorgQueries(activeShell)); // perform the refactoring and return its success result performRefactoring(refactoring); boolean status = wizard.getChange() != null; System.out.println(status); return status; } catch (JavaModelException e) { e.printStackTrace(); return false; } catch (OperationCanceledException e) { e.printStackTrace(); return false; } finally { pm.done(); } }