Java Code Examples for org.eclipse.core.resources.IResource#isLinked()
The following examples show how to use
org.eclipse.core.resources.IResource#isLinked() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static Change copyCuToPackage(ICompilationUnit cu, IPackageFragment dest, NewNameProposer nameProposer, INewNameQueries copyQueries) { // XXX workaround for bug 31998 we will have to disable renaming of // linked packages (and cus) IResource res= ReorgUtils.getResource(cu); if (res != null && res.isLinked()) { if (ResourceUtil.getResource(dest) instanceof IContainer) return copyFileToContainer(cu, (IContainer) ResourceUtil.getResource(dest), nameProposer, copyQueries); } String newName= nameProposer.createNewName(cu, dest); Change simpleCopy= new CopyCompilationUnitChange(cu, dest, copyQueries.createStaticQuery(newName)); if (newName == null || newName.equals(cu.getElementName())) return simpleCopy; try { IPath newPath= cu.getResource().getParent().getFullPath().append(JavaModelUtil.getRenamedCUName(cu, newName)); INewNameQuery nameQuery= copyQueries.createNewCompilationUnitNameQuery(cu, newName); return new CreateCopyOfCompilationUnitChange(newPath, cu.getSource(), cu, nameQuery); } catch (CoreException e) { // Using inferred change return simpleCopy; } }
Example 2
Source File: DeleteResourceAndCloseEditorAction.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * Asks the user to confirm a delete operation, where the selection contains no projects. * @param resources * the selected resources * @return <code>true</code> if the user says to go ahead, and <code>false</code> if the deletion should be * abandoned */ private boolean confirmDeleteNonProjects(IResource[] resources) { String title; String msg; if (resources.length == 1) { title = IDEWorkbenchMessages.DeleteResourceAction_title1; IResource resource = resources[0]; if (resource.isLinked()) { msg = NLS.bind(IDEWorkbenchMessages.DeleteResourceAction_confirmLinkedResource1, resource.getName()); } else { msg = NLS.bind(IDEWorkbenchMessages.DeleteResourceAction_confirm1, resource.getName()); } } else { title = IDEWorkbenchMessages.DeleteResourceAction_titleN; if (containsLinkedResource(resources)) { msg = NLS.bind(IDEWorkbenchMessages.DeleteResourceAction_confirmLinkedResourceN, new Integer( resources.length)); } else { msg = NLS.bind(IDEWorkbenchMessages.DeleteResourceAction_confirmN, new Integer(resources.length)); } } return MessageDialog.openQuestion(shellProvider.getShell(), title, msg); }
Example 3
Source File: AddSynchronizeAction.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
protected FastSyncInfoFilter getSyncInfoFilter() { return new FastSyncInfoFilter() { public boolean select(SyncInfo info) { SyncInfoDirectionFilter filter = new SyncInfoDirectionFilter(new int[] {SyncInfo.OUTGOING}); if (!filter.select(info)) return false; IStructuredSelection selection = getStructuredSelection(); Iterator iter = selection.iterator(); while (iter.hasNext()) { ISynchronizeModelElement element = (ISynchronizeModelElement)iter.next(); IResource resource = element.getResource(); if (resource == null) return false; if (resource.isLinked()) return false; ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource); try { if (svnResource.isManaged()) return false; } catch (SVNException e) { return false; } } return true; } }; }
Example 4
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static Change copyCuToPackage(ICompilationUnit cu, IPackageFragment dest, NewNameProposer nameProposer, INewNameQueries copyQueries) { // XXX workaround for bug 31998 we will have to disable renaming of // linked packages (and cus) IResource res= ReorgUtils.getResource(cu); if (res != null && res.isLinked()) { if (ResourceUtil.getResource(dest) instanceof IContainer) { return copyFileToContainer(cu, (IContainer) ResourceUtil.getResource(dest), nameProposer, copyQueries); } } String newName= nameProposer.createNewName(cu, dest); Change simpleCopy= new CopyCompilationUnitChange(cu, dest, copyQueries.createStaticQuery(newName)); if (newName == null || newName.equals(cu.getElementName())) { return simpleCopy; } try { IPath newPath= cu.getResource().getParent().getFullPath().append(JavaModelUtil.getRenamedCUName(cu, newName)); INewNameQuery nameQuery= copyQueries.createNewCompilationUnitNameQuery(cu, newName); return new CreateCopyOfCompilationUnitChange(newPath, cu.getSource(), cu, nameQuery); } catch (CoreException e) { // Using inferred change return simpleCopy; } }
Example 5
Source File: DeleteChangeCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static Change createPackageFragmentRootDeleteChange(IPackageFragmentRoot root) throws JavaModelException { IResource resource= root.getResource(); if (resource != null && resource.isLinked()){ //XXX using this code is a workaround for jcore bug 31998 //jcore cannot handle linked stuff //normally, we should always create DeletePackageFragmentRootChange CompositeChange composite= new DynamicValidationStateChange(RefactoringCoreMessages.DeleteRefactoring_delete_package_fragment_root); ClasspathChange change= ClasspathChange.removeEntryChange(root.getJavaProject(), root.getRawClasspathEntry()); if (change != null) { composite.add(change); } Assert.isTrue(! Checks.isClasspathDelete(root));//checked in preconditions composite.add(createDeleteChange(resource)); return composite; } else { Assert.isTrue(! root.isExternal()); // TODO remove the query argument return new DeletePackageFragmentRootChange(root, true, null); } }
Example 6
Source File: ResourceUtil.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private static boolean checkResource(IResource link, Path linkPath) throws CoreException, IOException { if (link.exists()) { // Eclipse resource already exists if (link.isLinked() || Files.isSymbolicLink(linkPath)) { // Remove the link link.delete(true, null); } else { // Abort because folder or file exists return false; } } if (Files.isSymbolicLink(linkPath)) { // Delete the broken file system symbolic link Files.delete(linkPath); } else if (linkPath.toFile().exists()) { // Abort because folder or file exists return false; } return true; }
Example 7
Source File: RenameTypeProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void createChanges(IProgressMonitor pm) throws CoreException { try { pm.beginTask("", 12); //$NON-NLS-1$ pm.setTaskName(RefactoringCoreMessages.RenameTypeProcessor_creating_changes); if (fUpdateReferences) { addReferenceUpdates(fChangeManager, new SubProgressMonitor(pm, 3)); } // Similar names updates have already been added. pm.worked(1); IResource resource = fType.getCompilationUnit().getResource(); // if we have a linked resource then we don't use CU renaming // directly. So we have to update the code by ourselves. if ((resource != null && resource.isLinked()) || !willRenameCU()) { addTypeDeclarationUpdate(fChangeManager); pm.worked(1); addConstructorRenames(fChangeManager); pm.worked(1); } else { pm.worked(2); } if (fUpdateTextualMatches) { pm.subTask(RefactoringCoreMessages.RenameTypeRefactoring_searching_text); TextMatchUpdater.perform(new SubProgressMonitor(pm, 1), RefactoringScopeFactory.create(fType), this, fChangeManager, fReferences); if (fUpdateSimilarElements) { addSimilarElementsTextualUpdates(fChangeManager, new SubProgressMonitor(pm, 3)); } } } finally { pm.done(); } }
Example 8
Source File: ReorgUtils.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static IResource[] getNotLinked(IResource[] resources) { Collection<IResource> result= new ArrayList<IResource>(resources.length); for (int i= 0; i < resources.length; i++) { IResource resource= resources[i]; if (resource != null && ! result.contains(resource) && ! resource.isLinked()) result.add(resource); } return result.toArray(new IResource[result.size()]); }
Example 9
Source File: ReadOnlyResourceFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean hasReadOnlyResourcesAndSubResources(IResource resource) throws CoreException { if (resource.isLinked()) //we don't want to count these because we never actually delete linked resources return false; if (Resources.isReadOnly(resource)) return true; if (resource instanceof IContainer) return hasReadOnlyResourcesAndSubResources(((IContainer)resource).members()); return false; }
Example 10
Source File: RenameSourceFolderChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static RefactoringStatus checkIfModifiable(IPackageFragmentRoot root) throws CoreException { RefactoringStatus result= new RefactoringStatus(); if (root == null) { result.addFatalError(RefactoringCoreMessages.DynamicValidationStateChange_workspace_changed); return result; } if (!root.exists()) { result.addFatalError(Messages.format(RefactoringCoreMessages.Change_does_not_exist, getRootLabel(root))); return result; } if (result.hasFatalError()) return result; if (root.isArchive()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_archive, getRootLabel(root))); return result; } if (root.isExternal()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_external, getRootLabel(root))); return result; } IResource correspondingResource= root.getCorrespondingResource(); if (correspondingResource == null || !correspondingResource.exists()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_error_underlying_resource_not_existing, getRootLabel(root))); return result; } if (correspondingResource.isLinked()) { result.addFatalError(Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_rename_linked, getRootLabel(root))); return result; } return result; }
Example 11
Source File: DeleteChangeCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static Change createSourceManipulationDeleteChange(ISourceManipulation element) { //XXX workaround for bug 31384, in case of linked ISourceManipulation delete the resource if (element instanceof ICompilationUnit || element instanceof IPackageFragment){ IResource resource; if (element instanceof ICompilationUnit) resource= ReorgUtils.getResource((ICompilationUnit)element); else resource= ((IPackageFragment)element).getResource(); if (resource != null && resource.isLinked()) return createDeleteChange(resource); } return new DeleteSourceManipulationChange(element, true); }
Example 12
Source File: ExternalFoldersManager.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Map getFolders() { if (this.folders == null) { Map tempFolders = new HashMap(); IProject project = getExternalFoldersProject(); try { if (!project.isAccessible()) { if (project.exists()) { // workspace was moved (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=252571 ) openExternalFoldersProject(project, null/*no progress*/); } else { // if project doesn't exist, do not open and recreate it as it means that there are no external folders return this.folders = Collections.synchronizedMap(tempFolders); } } IResource[] members = project.members(); for (int i = 0, length = members.length; i < length; i++) { IResource member = members[i]; if (member.getType() == IResource.FOLDER && member.isLinked() && member.getName().startsWith(LINKED_FOLDER_NAME)) { IPath externalFolderPath = member.getLocation(); tempFolders.put(externalFolderPath, member); } } } catch (CoreException e) { Util.log(e, "Exception while initializing external folders"); //$NON-NLS-1$ } this.folders = Collections.synchronizedMap(tempFolders); } return this.folders; }
Example 13
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static Change moveCuToPackage(ICompilationUnit cu, IPackageFragment dest) { // XXX workaround for bug 31998 we will have to disable renaming of // linked packages (and cus) IResource resource= cu.getResource(); if (resource != null && resource.isLinked()) { if (ResourceUtil.getResource(dest) instanceof IContainer) { return moveFileToContainer(cu, (IContainer) ResourceUtil.getResource(dest)); } } return new MoveCompilationUnitChange(cu, dest); }
Example 14
Source File: DeleteResourceAndCloseEditorAction.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Returns whether the selection contains linked resources. * @param resources * the selected resources * @return <code>true</code> if the resources contain linked resources, and <code>false</code> otherwise */ private boolean containsLinkedResource(IResource[] resources) { for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; if (resource.isLinked()) { return true; } } return false; }
Example 15
Source File: ActionUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static boolean mustDisableJavaModelAction(Shell shell, Object element) { if (!(element instanceof IPackageFragment) && !(element instanceof IPackageFragmentRoot)) return false; IResource resource= ResourceUtil.getResource(element); if ((resource == null) || (! (resource instanceof IFolder)) || (! resource.isLinked())) return false; MessageDialog.openInformation(shell, ActionMessages.ActionUtil_not_possible, ActionMessages.ActionUtil_no_linked); return true; }
Example 16
Source File: XdsRenameResourceChange.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
public Change perform(IProgressMonitor pm) throws CoreException { try { pm.beginTask(RefactoringCoreMessages.RenameResourceChange_progress_description, 1); IResource resource= getResource(); File absoluteFile = ResourceUtils.getAbsoluteFile(resource); IPath destPath = renamedResourcePath(resource.getRawLocation(), fNewName); boolean isLinked = resource.isLinked(); long currentStamp= resource.getModificationStamp(); IPath newPath= renamedResourcePath(fResourcePath, fNewName); IFile destIFile = ResourceUtils.getWorkspaceRoot().getFile(newPath); Change undoDeleteChange = null; if (destIFile.exists()) { // handle rename conflict DeleteResourceChange deleteChange = new DeleteResourceChange(destIFile.getFullPath(), true); undoDeleteChange = deleteChange.perform(pm); } resource.move(newPath, IResource.SHALLOW, pm); if (isLinked) { File dest = destPath.toFile(); FileUtils.deleteQuietly(dest); absoluteFile.renameTo(dest); // get the resource again since after move resource can be inadequate IWorkspaceRoot workspaceRoot = ResourceUtils.getWorkspaceRoot(); resource = workspaceRoot.getFile(newPath); ((IFile)resource).createLink(destPath, IResource.REPLACE, new NullProgressMonitor()); } if (fStampToRestore != IResource.NULL_STAMP) { IResource newResource= ResourcesPlugin.getWorkspace().getRoot().findMember(newPath); newResource.revertModificationStamp(fStampToRestore); } String oldName= fResourcePath.lastSegment(); XdsRenameResourceChange undoRenameChange = new XdsRenameResourceChange(newPath, oldName, currentStamp); if (undoDeleteChange == null) { return undoRenameChange; } else { return new CompositeChange(getName(), new Change[]{undoRenameChange, undoDeleteChange}); // constructing undo changes } } finally { pm.done(); } }
Example 17
Source File: BaseDocumentLifeCycleHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private ICompilationUnit checkPackageDeclaration(String uri, ICompilationUnit unit) { if (unit.getResource() != null && unit.getJavaProject() != null && unit.getJavaProject().getProject().getName().equals(ProjectsManager.DEFAULT_PROJECT_NAME)) { try { CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, new NullProgressMonitor()); IProblem[] problems = astRoot.getProblems(); for (IProblem problem : problems) { if (problem.getID() == IProblem.PackageIsNotExpectedPackage) { IResource file = unit.getResource(); boolean toRemove = file.isLinked(); if (toRemove) { IPath path = file.getParent().getProjectRelativePath(); if (path.segmentCount() > 0 && JDTUtils.SRC.equals(path.segments()[0])) { String packageNameResource = path.removeFirstSegments(1).toString().replace(JDTUtils.PATH_SEPARATOR, JDTUtils.PERIOD); path = file.getLocation(); if (path != null && path.segmentCount() > 0) { path = path.removeLastSegments(1); String pathStr = path.toString().replace(JDTUtils.PATH_SEPARATOR, JDTUtils.PERIOD); if (pathStr.endsWith(packageNameResource)) { toRemove = false; } } } } if (toRemove) { file.delete(true, new NullProgressMonitor()); if (unit.equals(sharedASTProvider.getActiveJavaElement())) { sharedASTProvider.disposeAST(); } unit.discardWorkingCopy(); unit = JDTUtils.resolveCompilationUnit(uri); unit.becomeWorkingCopy(new NullProgressMonitor()); triggerValidation(unit); } break; } } } catch (CoreException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } } return unit; }
Example 18
Source File: DeleteWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean isLinked(IResource resource) { return resource != null && resource.isLinked(); }
Example 19
Source File: SVNWorkspaceRoot.java From APICloud-Studio with GNU General Public License v3.0 | 2 votes |
/** * Return true if the resource is part of a link (i.e. a linked resource or * one of it's children. * * @param container * @return boolean */ public static boolean isLinkedResource(IResource resource) { return resource.isLinked(IResource.CHECK_ANCESTORS); }