/** * Final check before the actual refactoring * * @return status * @throws OperationCanceledException */ public RefactoringStatus checkFinalConditions() throws OperationCanceledException { RefactoringStatus status = new RefactoringStatus(); IContainer destination = fProcessor.getDestination(); IProject sourceProject = fProcessor.getSourceSelection()[0].getProject(); IProject destinationProject = destination.getProject(); if (sourceProject != destinationProject) status.merge(MoveUtils.checkMove(phpFiles, sourceProject, destination)); // Checks if one of the resources already exists with the same name in // the destination IPath dest = fProcessor.getDestination().getFullPath(); IResource[] sourceResources = fProcessor.getSourceSelection(); for (IResource element : sourceResources) { String newFilePath = dest.toOSString() + File.separatorChar + element.getName(); IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(newFilePath)); if (resource != null && resource.exists()) { status.merge( RefactoringStatus.createFatalErrorStatus( NLS.bind( PhpRefactoringCoreMessages.getString("MoveDelegate.6"), element.getName(), dest.toOSString()))); // $NON-NLS-1$ } } return status; }
private void removeBuildPath(IResource resource, IProject project) { IScriptProject projrct = DLTKCore.create(project); IPath filePath = resource.getFullPath(); oldBuildEntries = Arrays.asList(projrct.readRawBuildpath()); newBuildEntries = new ArrayList<IBuildpathEntry>(); newBuildEntries.addAll(oldBuildEntries); for (int i = 0; i < oldBuildEntries.size(); i++) { IBuildpathEntry fEntryToChange = oldBuildEntries.get(i); IPath entryPath = fEntryToChange.getPath(); int mattchedPath = entryPath.matchingFirstSegments(filePath); if (mattchedPath == filePath.segmentCount()) { newBuildEntries.remove(fEntryToChange); } else { IBuildpathEntry newEntry = RefactoringUtility.createNewBuildpathEntry( fEntryToChange, fEntryToChange.getPath(), filePath, ""); // $NON-NLS-1$ newBuildEntries.remove(fEntryToChange); newBuildEntries.add(newEntry); } } oldIncludePath = new ArrayList<IBuildpathEntry>(); newIncludePathEntries = new ArrayList<IBuildpathEntry>(); List<IncludePath> includePathEntries = Arrays.asList(IncludePathManager.getInstance().getIncludePaths(project)); for (IncludePath entry : includePathEntries) { Object includePathEntry = entry.getEntry(); IResource includeResource = null; if (!(includePathEntry instanceof IBuildpathEntry)) { includeResource = (IResource) includePathEntry; IPath entryPath = includeResource.getFullPath(); IBuildpathEntry oldEntry = RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath); oldIncludePath.add((IBuildpathEntry) oldEntry); if (filePath.isPrefixOf(entryPath) || entryPath.equals(filePath)) { } else { IBuildpathEntry newEntry = RefactoringUtility.createNewBuildpathEntry(IBuildpathEntry.BPE_SOURCE, entryPath); newIncludePathEntries.add(newEntry); } } else { newIncludePathEntries.add((IBuildpathEntry) includePathEntry); oldIncludePath.add((IBuildpathEntry) includePathEntry); } } }
private void createRunConfigurationChange( IResource[] sourceResources, CompositeChange rootChange) { IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources); for (IResource element : uniqueSourceResources) { RenameConfigurationChange configPointchanges = new RenameConfigurationChange( element.getFullPath().removeLastSegments(1), fMainDestinationPath, element.getName(), element.getName()); rootChange.add(configPointchanges); } }
private void createRenameLibraryFolderChange( IResource[] sourceResources, CompositeChange rootChange) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); LibraryFolderManager lfm = LibraryFolderManager.getInstance(); for (IResource resource : sourceResources) { if (resource.getType() == IResource.FOLDER && lfm.isInLibraryFolder(resource)) { IPath newPath = fMainDestinationPath.append(resource.getName()); IFolder newFolder = root.getFolder(newPath); RenameLibraryFolderChange change = new RenameLibraryFolderChange((IFolder) resource, newFolder); rootChange.add(change); } } }
private void createBreakPointChange(IResource[] sourceResources, CompositeChange rootChange) throws CoreException { IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources); for (IResource element : uniqueSourceResources) { collectBrakePoint(element); RenameBreackpointChange breakePointchanges = new RenameBreackpointChange( element.getFullPath().removeLastSegments(1), fMainDestinationPath, element.getName(), element.getName(), fBreakpoints, fBreakpointAttributes); if (fBreakpoints.getKeys().size() > 0) { rootChange.add(breakePointchanges); } } }
protected void collectBrakePoint(IResource resource) throws CoreException { fBreakpoints = new BucketMap<IResource, IBreakpoint>(6); fBreakpointAttributes = new HashMap<IBreakpoint, Map<String, Object>>(6); final IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager(); IMarker[] markers = resource.findMarkers(IBreakpoint.LINE_BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); for (IMarker marker : markers) { IResource markerResource = marker.getResource(); IBreakpoint breakpoint = breakpointManager.getBreakpoint(marker); if (breakpoint != null) { fBreakpoints.add(markerResource, breakpoint); fBreakpointAttributes.put(breakpoint, breakpoint.getMarker().getAttributes()); } } }
private IResource[] removeDuplicateResources(IResource[] sourceResources) { // ignore empty array if (sourceResources == null || sourceResources.length == 0) { return sourceResources; } ArrayList<IResource> result = new ArrayList<IResource>(); for (IResource source : sourceResources) { if (result.size() == 0) { result.add(source); } else { // check if the resource is parent of any item in the result for (IResource existing : result) { // if the resource is parent of an existing item in the // result. // remove the existing item, add the new one. if (source.getFullPath().isPrefixOf(existing.getFullPath())) { result.remove(existing); result.add(source); } } boolean noNeedAdded = false; for (IResource existing : result) { // if the resource is parent of an existing item in the // result. // remove the existing item, add the new one. if (existing.getFullPath().isPrefixOf(source.getFullPath())) { noNeedAdded = true; } } // the source is not in the result after loop if (!result.contains(source) && !noNeedAdded) { result.add(source); } } } IResource[] ret = new IResource[result.size()]; return result.toArray(ret); }
/** * Checks whether the given move included is vaild * * @param destination * @return a staus indicating whether the included is valid or not */ public RefactoringStatus verifyDestination(IResource destination) { RefactoringStatus status = new RefactoringStatus(); Assert.isNotNull(destination); if (!destination.exists() || destination.isPhantom()) return RefactoringStatus.createFatalErrorStatus( PhpRefactoringCoreMessages.getString("MoveDelegate.2")); // $NON-NLS-1$ if (!destination.isAccessible()) return RefactoringStatus.createFatalErrorStatus( PhpRefactoringCoreMessages.getString("MoveDelegate.3")); // $NON-NLS-1$ Assert.isTrue(destination.getType() != IResource.ROOT); IResource[] sourceResources = fProcessor.getSourceSelection(); for (IResource element : sourceResources) { if (destination.equals(element.getParent())) return RefactoringStatus.createFatalErrorStatus( PhpRefactoringCoreMessages.getString("MoveDelegate.4")); // $NON-NLS-1$ if (destination.equals(element)) { return RefactoringStatus.createFatalErrorStatus( PhpRefactoringCoreMessages.getString("MoveDelegate.5")); // $NON-NLS-1$ } } return status; }
private void createBuildPathChange(IResource[] sourceResources, CompositeChange rootChange) throws ModelException { IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources); for (IResource element : uniqueSourceResources) { // only container need handle build/include path. if (element instanceof IContainer) { IProject project = element.getProject(); // if moving to another project if (RefactoringUtility.getResource(fMainDestinationPath).getProject() != project) { removeBuildPath(element, project); IPath path = element.getFullPath().removeLastSegments(1); RenameBuildAndIcludePathChange biChange = new RenameBuildAndIcludePathChange( path, path, element.getName(), "", oldBuildEntries, //$NON-NLS-1$ newBuildEntries, oldIncludePath, newIncludePathEntries); if (newBuildEntries.size() > 0 || newIncludePathEntries.size() > 0) { rootChange.add(biChange); } } else { updateBuildPath(element, project); RenameBuildAndIcludePathChange biChange = new RenameBuildAndIcludePathChange( element.getFullPath().removeLastSegments(1), fMainDestinationPath, element.getName(), element.getName(), oldBuildEntries, newBuildEntries, oldIncludePath, newIncludePathEntries); if (newBuildEntries.size() > 0 || newIncludePathEntries.size() > 0) { rootChange.add(biChange); } } } } }