Java Code Examples for org.eclipse.core.resources.IResourceDelta#getResource()
The following examples show how to use
org.eclipse.core.resources.IResourceDelta#getResource() .
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: ProjectDeltaVisitor.java From saros with GNU General Public License v2.0 | 6 votes |
private boolean handleFolderDelta(IResourceDelta delta) { IResource resource = delta.getResource(); int kind = delta.getKind(); switch (kind) { case IResourceDelta.ADDED: generateCreated(resource); return true; case IResourceDelta.REMOVED: generateRemoved(resource); return true; default: return kind != IResourceDelta.NO_CHANGE; } }
Example 2
Source File: PydevGrouperVisitor.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * This will use the internal builders to traverse the delta. Note that the resource is always a valid * python file and is also always located in the pythonpath. */ @Override protected void onVisitDelta(IResourceDelta delta) { //Note: removals happen now, additions and changes happen later (so that renames are //properly treated). switch (delta.getKind()) { case IResourceDelta.ADDED: case IResourceDelta.CHANGED: delayedVisits.add(delta); break; case IResourceDelta.REMOVED: IResource resource = delta.getResource(); memo.put(PyDevBuilderVisitor.DOCUMENT_TIME, System.currentTimeMillis()); visitRemovedResource(resource, null, monitor); break; } }
Example 3
Source File: ProblemManager.java From typescript.java with MIT License | 5 votes |
@Override public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); if (resource instanceof IProject && delta.getKind() == IResourceDelta.CHANGED) { IProject project = (IProject) resource; if (!project.isAccessible()) { return false; // skip closed projects } } checkInvalidate(delta, resource); return true; }
Example 4
Source File: ChangedSpecModulesGatheringDeltaVisitor.java From tlaplus with MIT License | 5 votes |
/** * If the delta points to a module in the currently loaded spec, it adds that resource to * the list modules. * If the delta points to the file of the configuration, then it sets model equal to * that file. * If the delta points to a resouce that is the model directory for the configuration in * the constructor, then sets checkpointsChanged to true. * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) */ /* (non-Javadoc) * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) */ public boolean visit(IResourceDelta delta) throws CoreException { final IResource resource = delta.getResource(); // TLCActivator.getDefault().logDebug("resource = " + resource.getFullPath().toString()); if (IResource.FILE == resource.getType()) { // add the file only if it's parent is the root file's parent. if (ResourceHelper.isModule(resource) && (resource.getParent().equals(rootFileParent))) { // TLCActivator.getDefault().logDebug("module resource added"); modules.add(resource); } else // The first conjunct of the following test should probably be ((delta.getFlags() & IResourceDelta.MARKERS) // == IResourceDelta.MARKERS), // but it doesn't hurt to remove that test and risk unnecessarily removing and resetting markers. if (/* delta.getFlags() == IResourceDelta.MARKERS && */(getModel() != null) && getModel().equals(resource)) { // TLCActivator.getDefault().logDebug("model set to resource"); model = resource; return false; } } else if (IResource.FOLDER == resource.getType()) { if ((modelDir != null) && (modelDir.exists()) && (modelDir.equals(resource))) { checkpointsChanged = true; return false; } } // TODO: we don't really want the visitor to visit the whole tree, do we? return true; }
Example 5
Source File: BuildscriptGenerator.java From cmake4eclipse with Eclipse Public License 2.0 | 5 votes |
public boolean visit(IResourceDelta delta) { switch (delta.getKind()) { case IResourceDelta.CHANGED: IResource resource = delta.getResource(); if (resource.getType() == IResource.FILE && resource.getName().equals("CMakeLists.txt")) { hasChanges= true; return false; } } return true; }
Example 6
Source File: RevertResourceManager.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Revert previously deleted resources that are added again. When a file is * reverted, it's parent directories are also reverted. * When new files are added in folders that are scheduled for deletion, the parent * folder tree is reverted. * * @param resources */ private ISVNLocalResource[] processResources(IResourceDelta[] resources) throws CoreException { List<ISVNLocalResource> revertedResources = new ArrayList<ISVNLocalResource>(); for (IResourceDelta resourceDelta : resources) { IResource resource = resourceDelta.getResource(); if (resource.getType() == IResource.FILE) { ISVNLocalFile res = SVNWorkspaceRoot.getSVNFileFor((IFile) resource); if (res.getFile().exists()) { boolean deleted; if (resourceDelta.getKind() == IResourceDelta.ADDED) deleted = res.getStatusFromCache().isDeleted(); else { deleted = SVNMoveDeleteHook.isDeleted((IFile)resource); if (deleted) SVNMoveDeleteHook.removeFromDeletedFileList((IFile)resource); } if (deleted) { revertedResources.add(res); } ISVNLocalFolder parentFolder = res.getParent(); while (parentFolder != null) { if (parentFolder.getStatusFromCache().isDeleted() && !parentFolder.getResource().exists() && !revertedResources.contains(parentFolder)) { revertedResources.add(parentFolder); } else { break; } if (parentFolder.getParent() == null) { break; } parentFolder = parentFolder.getParent(); } } } } return (ISVNLocalResource[]) revertedResources.toArray(new ISVNLocalResource[revertedResources.size()]); }
Example 7
Source File: BundleMonitor.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * isProjectBundleFile * * @param delta * @return */ private boolean isProjectBundleFile(IResourceDelta delta) { String fullProjectPath = delta.getFullPath().toString(); boolean result = false; if (BUNDLE_PATTERN_DEPRECATED.matcher(fullProjectPath).matches() || BUNDLE_PATTERN.matcher(fullProjectPath).matches()) { // always return true for bundle.rb files result = true; } else if (FILE_PATTERN_DEPRECATED.matcher(fullProjectPath).matches() || FILE_PATTERN.matcher(fullProjectPath).matches()) { // only return true if the script is part of an existing bundle. IResource resource = delta.getResource(); if (resource != null) { IPath location = resource.getLocation(); if (location != null) { File script = delta.getResource().getLocation().toFile(); result = isScriptInExistingBundle(script); } } } return result; }
Example 8
Source File: ExternalBreakpointWatcher.java From goclipse with Eclipse Public License 1.0 | 5 votes |
@Override public void resourceChanged(IResourceChangeEvent event) { IResourceDelta delta = event.getDelta(); if(delta == null) { return; } IResource res = delta.getResource(); if(res instanceof IWorkspaceRoot && (delta.getFlags() & IResourceDelta.MARKERS) != 0) { IMarkerDelta[] markerDeltas = delta.getMarkerDeltas(); for (IMarkerDelta markerDelta : markerDeltas) { int kind = markerDelta.getKind(); if(markerDelta.isSubtypeOf(CBREAKPOINT_MARKER_TYPE)) { if (kind == IResourceDelta.ADDED) { addMarkerAnnotation(markerDelta.getMarker()); } if (kind == IResourceDelta.REMOVED) { removeMarkerAnnotation(markerDelta.getMarker()); } if (kind == IResourceDelta.CHANGED) { updateMarkerAnnotation(markerDelta.getMarker()); } } } } }
Example 9
Source File: ToolboxDirectoryVisitor.java From tlaplus with MIT License | 5 votes |
/** * The visit method gets a resource and returns true or false depending on * whether or not it wants to be called with the children of the resource. * In this case, we return true unless the resource is a project representing * a spec (and thus whose resource is stored as a File (in this case a directory) * with extension toolbox. * * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) */ public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); if ((resource instanceof IProject) ) { iprojects.add((IProject) resource); return false; } return true; }
Example 10
Source File: ProjectBuilder.java From neoscada with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit ( final IResourceDelta delta ) { final IResource resource = delta.getResource (); return handleResource ( delta, resource, this.adapterFactory, this.extensions, this.monitor ); }
Example 11
Source File: CheckoutUsingProjectWizardAction.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) */ public void resourceChanged(IResourceChangeEvent event) { IResourceDelta root = event.getDelta(); IResourceDelta[] projectDeltas = root.getAffectedChildren(); for (int i = 0; i < projectDeltas.length; i++) { IResourceDelta delta = projectDeltas[i]; IResource resource = delta.getResource(); if (delta.getKind() == IResourceDelta.ADDED) { newProject = (IProject)resource; } } }
Example 12
Source File: ProjectStateChangeListener.java From n4js with Eclipse Public License 1.0 | 5 votes |
private boolean collectAffectedProjects(IResourceDelta delta, Set<IProject> accumulator) { IResource resource = delta.getResource(); if (resource instanceof IProject && "RemoteSystemsTempFiles".equals(resource.getName())) { return false; } if (resource instanceof IWorkspaceRoot) return true; if (resource instanceof IProject) { IProject project = (IProject) resource; if ("RemoteSystemsTempFiles".equals(resource.getName())) { return false; } if ((delta.getKind() & IResourceDelta.CHANGED) != 0 && project.isOpen()) { if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { accumulator.add(project); } if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) { if ((delta.findMember(new Path(".project")) != null) && XtextProjectHelper.hasNature(project) && XtextProjectHelper.hasBuilder(project)) { accumulator.add(project); } } } return true; } if (resource instanceof IFolder) { if (N4JSGlobals.NODE_MODULES.equals(resource.getName())) { accumulator.add(resource.getProject()); } else if ((delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) && isSourceContainerModification(resource)) { accumulator.add(resource.getProject()); } } return false; }
Example 13
Source File: N4JSAllContainersState.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Handles the given {@link IResourceDelta} and updates the project state (cache of available projects and project * descriptions) accordingly. * * If so, invalidates the {@link EclipseBasedN4JSWorkspace} cache of project descriptions for the updated projects. */ private boolean updateProjectState(IResourceDelta delta) { if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.REMOVED) { if (IN4JSProject.PACKAGE_JSON.equals(delta.getFullPath().lastSegment())) { return true; } if (delta.getResource() instanceof IProject) { return true; } if (delta.getResource() instanceof IFolder) { if (isSourceContainerModification(delta)) { return true; } } return false; } else if (delta.getKind() == IResourceDelta.CHANGED) { if (delta.getResource() instanceof IProject) { if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { return true; } return false; } if (delta.getResource() instanceof IFolder) { if (N4JSGlobals.NODE_MODULES.equals(delta.getFullPath().lastSegment())) { return true; } return false; } } if (packageJSONFileHasBeenChanged(delta)) { return true; } return false; }
Example 14
Source File: ToStringResourceDeltaVisitor.java From saros with GNU General Public License v2.0 | 4 votes |
@Override public boolean visit(IResourceDelta delta) throws CoreException { boolean result = true; switch (delta.getKind()) { case IResourceDelta.NO_CHANGE: sb.append("0"); result = false; break; case IResourceDelta.CHANGED: sb.append("C("); int f = delta.getFlags(); if (f == 0) { sb.append("0) "); } else { Set<Entry<Integer, String>> entrySet = map.entrySet(); for (Entry<Integer, String> entry : entrySet) { if (0 != (f & entry.getKey())) sb.append(entry.getValue()); } sb.append(") "); } break; case IResourceDelta.ADDED: sb.append("A "); break; case IResourceDelta.REMOVED: sb.append("R "); break; default: sb.append("? "); } IResource resource = delta.getResource(); if (resource != null) { if (resource.isDerived()) sb.append("* "); if (resource.isPhantom()) sb.append("P "); if (resource.isHidden()) sb.append("H "); sb.append(resource.getFullPath().toPortableString()); } else { sb.append("No resource"); } sb.append("\n"); return result; }
Example 15
Source File: XtextBuilder.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected boolean isOpened(IResourceDelta delta) { return delta.getResource() instanceof IProject && (delta.getFlags() & IResourceDelta.OPEN) != 0 && ((IProject) delta.getResource()).isOpen(); }
Example 16
Source File: ResourceDeltaVisitor.java From saros with GNU General Public License v2.0 | 4 votes |
@Override public boolean visit(final IResourceDelta delta) throws CoreException { final IResource resource = delta.getResource(); if (resource.getType() == IResource.ROOT) return true; if (!session.isShared(ResourceAdapterFactory.create(resource))) return true; if (resource.getType() != IResource.PROJECT) { isModifyingResources = true; return false; } if (delta.getKind() == IResourceDelta.REMOVED) { if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) isMovingProject = true; else isDeletingProject = true; return false; } return true; }
Example 17
Source File: ProjectDeltaVisitor.java From saros with GNU General Public License v2.0 | 4 votes |
private void handleFileDelta(IResourceDelta delta) { IResource resource = delta.getResource(); int kind = delta.getKind(); IProject project = resource.getProject(); boolean contentChange = isContentChange(delta); /* * TODO Generate better move deltas, e.g we share multiple projects and * a file is moved between those projects. Currently we generate a * delete and create activity. */ switch (kind) { case IResourceDelta.CHANGED: if (contentChange) generateContentChanged(resource); return; case IResourceDelta.ADDED: // Was this file moved or renamed? if (isMovedFrom(delta)) { // Adds have getMovedFrom set: IPath oldFullPath = delta.getMovedFromPath(); IProject oldProject = getProject(oldFullPath); if (project.equals(oldProject)) { // Moving inside this project generateMoved(resource, oldFullPath, oldProject, contentChange); return; } /* * else moving a file into the shared project , treat like an * add! Fall-through ... */ } generateCreated(resource); return; case IResourceDelta.REMOVED: if (isMoved(delta)) { // REMOVED deltas have MovedTo set IPath newPath = delta.getMovedToPath(); IProject newProject = ProjectDeltaVisitor.getProject(newPath); // Ignore "REMOVED" while moving into shared project if (project.equals(newProject)) return; /* * else moving file away from shared project, need to tell * others to delete! Fall-through... */ } generateRemoved(resource); return; default: return; } }
Example 18
Source File: PydevInternalResourceDeltaVisitor.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * Visits the resource delta tree determining which files to rebuild (*.py). * * Subclasses should only reimplement visitChanged, visitAdded and visitRemoved. This method will not be called * in the structure provided by pydev. * * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) */ @Override public boolean visit(IResourceDelta delta) throws CoreException { if (delta == null) { return true; } final IResource resource = delta.getResource(); if (resource == null) { return true; } int type = resource.getType(); //related bug https://sourceforge.net/tracker/index.php?func=detail&aid=1238850&group_id=85796&atid=577329 //the team-support plugins of eclipse use the IResource //method setTeamPrivateMember to indicate resources //that are only in the project for the team-stuff (e.g. .svn or //.cvs or _darcs directories). if (resource.isTeamPrivateMember()) { return true; } if (type == IResource.FOLDER) { switch (delta.getKind()) { case IResourceDelta.REMOVED: memo.put(PyDevBuilderVisitor.DOCUMENT_TIME, System.currentTimeMillis()); visitRemovedResource(resource, null, monitor); break; //for folders, we don't have to do anything if added or changed (we just treat their children, that should //resolve for modules -- we do, however have to treat __init__.py differently). } } else if (type == IResource.FILE) { String ext = resource.getFileExtension(); if (ext == null) { //resource.getFileExtension() may return null if it has none. if (resource instanceof IFile) { CorePlugin.markAsPyDevFileIfDetected((IFile) resource); } return true; } //only analyze projects with the python nature... IProject project = resource.getProject(); PythonNature nature = PythonNature.getPythonNature(project); if (project != null && nature != null) { //we just want to make the visit if it is a valid python file and it is in the pythonpath if (PythonPathHelper.isValidSourceFile("." + ext)) { onVisitDelta(delta); } else if (ext.equals("pyc")) { if (delta.getKind() == IResourceDelta.ADDED) { handleAddedPycFiles(resource, nature); } } } } return true; }
Example 19
Source File: TLAParsingBuilder.java From tlaplus with MIT License | 4 votes |
/** * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) */ public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); if (resource.exists() && IResource.FILE == resource.getType()) { // a file found if (ResourceHelper.isModule(resource)) { // if the spec is null, this means that we are unable to get // access to the spec manager // because it has not yet been instantiatec. Instantiating // it would trigger a resource change // event which is not allowed if (spec == null) { modules.add(resource); } else if (spec.getRootFile().getParent().equals(resource.getParent())) { // we are only concerned with modules in the same // directory as the root module because those are the // only ones allowed to be a part of the spec if (resource.getPersistentProperty(TLAParsingBuilderConstants.LAST_BUILT) == null) { if (spec.getStatus() < IParseConstants.PARSED && spec.getStatus() > IParseConstants.UNKNOWN) { // If the property has never been set, the // resource has never been built. If the // current status is parsed, then it cannot be // relevant because it would have been built // if it were relevant. If the status is // unknown, it should remain unknown. In all // other cases, it is possible that the resource // is relevant but it is not known because there // was not a successful parse. Conservatively we // should consider it relevant. modules.add(resource); } } // If there current spec status is a problem status (see // AdaptorFactory.isProblemStatus), // then it is not known whether a given resource is // relevant so all resources are considered // relevant. Relevant resources are not necessarily in // dependancy storage. Any resource that is // out of build when the parse status is error is added to // the list of modules. else if (Long.parseLong(resource.getPersistentProperty(TLAParsingBuilderConstants.LAST_BUILT)) < resource .getLocalTimeStamp() && (dependancyTable.containsKey(resource.getName()) || (spec.getStatus() < IParseConstants.PARSED && spec .getStatus() > IParseConstants.UNPARSED))) { modules.add(resource); } } } } // we want the visitor to visit the whole tree return true; }
Example 20
Source File: DeltaProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void elementRemoved(Openable element, IResourceDelta delta, RootInfo rootInfo) { int elementType = element.getElementType(); if (delta == null || (delta.getFlags() & IResourceDelta.MOVED_TO) == 0) { // regular element removal if (isPrimaryWorkingCopy(element, elementType) ) { // filter out changes to primary compilation unit in working copy mode // just report a change to the resource (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59500) currentDelta().changed(element, IJavaElementDelta.F_PRIMARY_RESOURCE); } else { close(element); removeFromParentInfo(element); currentDelta().removed(element); } } else { // element is moved close(element); removeFromParentInfo(element); IPath movedToPath = delta.getMovedToPath(); IResource res = delta.getResource(); IResource movedToRes; switch (res.getType()) { case IResource.PROJECT: movedToRes = res.getWorkspace().getRoot().getProject(movedToPath.lastSegment()); break; case IResource.FOLDER: movedToRes = res.getWorkspace().getRoot().getFolder(movedToPath); break; case IResource.FILE: movedToRes = res.getWorkspace().getRoot().getFile(movedToPath); break; default: return; } // find the element type of the moved from element IPath rootPath = externalPath(movedToRes); RootInfo movedToInfo = enclosingRootInfo(rootPath, IResourceDelta.ADDED); int movedToType = elementType( movedToRes, IResourceDelta.ADDED, element.getParent().getElementType(), movedToInfo); // reset current element as it might be inside a nested root (popUntilPrefixOf() may use the outer root) this.currentElement = null; // create the moved To element Openable movedToElement = elementType != IJavaElement.JAVA_PROJECT && movedToType == IJavaElement.JAVA_PROJECT ? null : // outside classpath createElement(movedToRes, movedToType, movedToInfo); if (movedToElement == null) { // moved outside classpath currentDelta().removed(element); } else { currentDelta().movedFrom(element, movedToElement); } } switch (elementType) { case IJavaElement.JAVA_MODEL : this.manager.indexManager.reset(); break; case IJavaElement.JAVA_PROJECT : this.state.updateRoots(element.getPath(), delta, this); // remember that the project's cache must be reset this.projectCachesToReset.add(element); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT : JavaProject project = (JavaProject) element.getJavaProject(); // remember that the project's cache must be reset this.projectCachesToReset.add(project); break; case IJavaElement.PACKAGE_FRAGMENT : // reset package fragment cache project = (JavaProject) element.getJavaProject(); this.projectCachesToReset.add(project); break; } }