Java Code Examples for org.eclipse.core.resources.IResourceDelta#accept()

The following examples show how to use org.eclipse.core.resources.IResourceDelta#accept() . 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: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
public synchronized void resourceChanged(IResourceChangeEvent event) {
	if (event.getType() == IResourceChangeEvent.PRE_CLOSE)
		handleCloseEvent(event);

	IResourceDelta delta = event.getDelta();
	try {
		changedFiles.clear();
		if (delta != null)
			delta.accept(this);
		if (changedFiles.size() > 0) {
			handleHotModelReplacement();
		}

	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: ResourceUtils.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
public static Multimap<IProject, IFile> getAffectedFiles(IResourceDelta topDelta)
    throws CoreException {
  Multimap<IProject, IFile> files = HashMultimap.create();
  if (topDelta == null) {
    return files;
  }

  topDelta.accept(
      delta -> {
        if (delta.getResource() instanceof IFile) {
          IFile file = (IFile) delta.getResource();
          files.put(file.getProject(), file);
          return false;
        } else {
          return true;
        }
      });
  return files;
}
 
Example 3
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param monitor the progress monitor to use for reporting progress to the user. It is the caller's responsibility
 *        to call done() on the given monitor. Accepts null, indicating that no progress should be
 *        reported and that the operation cannot be cancelled.
 */
protected void incrementalBuild(IResourceDelta delta, final IProgressMonitor monitor) throws CoreException {
	final SubMonitor progress = SubMonitor.convert(monitor, Messages.XtextBuilder_CollectingResources, 10);
	progress.subTask(Messages.XtextBuilder_CollectingResources);
	
	pollQueuedBuildData();

	final ToBeBuilt toBeBuilt = new ToBeBuilt();
	IResourceDeltaVisitor visitor = createDeltaVisitor(toBeBuiltComputer, toBeBuilt, progress);
	delta.accept(visitor);

	if (progress.isCanceled()) {
		throw new OperationCanceledException();
	}
	progress.worked(2);
	Task task = closedProjectsQueue.exhaust();
	try {
		addInfosFromTaskAndBuild(task, toBeBuilt, BuildType.INCREMENTAL, progress.split(8));
	} catch(Exception e) {
		task.reschedule();
		throw e;
	}
}
 
Example 4
Source File: SearchResultUpdater.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private void handleDelta(IResourceDelta d) {
    try {
        d.accept(new IResourceDeltaVisitor() {
            @Override
            public boolean visit(IResourceDelta delta) throws CoreException {
                switch (delta.getKind()) {
                    case IResourceDelta.ADDED:
                        return false;
                    case IResourceDelta.REMOVED:
                        IResource res = delta.getResource();
                        if (res instanceof IFile) {
                            Match[] matches = fResult.getMatches(res);
                            fResult.removeMatches(matches);
                        }
                        break;
                    case IResourceDelta.CHANGED:
                        // handle changed resource (remove existing matches and redo search in file).
                        break;
                }
                return true;
            }
        });
    } catch (CoreException e) {
        Log.log(e);
    }
}
 
Example 5
Source File: CodewindResourceChangeListener.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();

	CodewindResourceDeltaVisitor visitor = new CodewindResourceDeltaVisitor();

	try {

		// If the delta is null (as happens with some events), just pass the empty array
		// list below.
		if (delta != null) {
			delta.accept(visitor);
		}

		parent.handleResourceChanges(visitor.getResult());

	} catch (CoreException e1) {
		// TODO: Log me.
		e1.printStackTrace();
	}

}
 
Example 6
Source File: BibtexEntryView.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event) {
	IResourceDelta delta = event.getDelta();
	if (delta != null) {
		try {
			delta.accept(markerVisitor);
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
}
 
Example 7
Source File: JReFrameworkerBuilder.java    From JReFrameworker with MIT License 5 votes vote down vote up
/**
 * Incrementally builds the project given a set of file changes
 * 
 * Reference: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2FresAdv_builders.htm
 * 
 * @param delta
 * @param monitor
 * @throws CoreException
 */
protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
	if(JReFrameworkerPreferences.isVerboseLoggingEnabled()) Log.info("Incremental Build");
	JReFrameworkerProject jrefProject = incrementalBuilder.getJReFrameworkerProject();
	BuildDeltaVisitor deltaVisitor = new BuildDeltaVisitor(jrefProject);
	delta.accept(deltaVisitor);
	if(!deltaVisitor.getDeltaBuildFilesToProcess().isEmpty()){
		// TODO: this could be improved to just detect changes to individual libraries...but too much work for now...
		// changes to the build file require a full build
		clean(monitor);
	} else {
		// process incremental changes
		// changes could be to source code, which will change the class files
		// changes could also be to class files only (if a build error was resolved but the source was not touched)
		Set<DeltaSource> sourceDeltas = deltaVisitor.getDeltaSourcesToProcess();
		if(!sourceDeltas.isEmpty()){
			try {
				IncrementalBuilder.PostBuildAction postBuildAction = incrementalBuilder.build(sourceDeltas, monitor);
				if(postBuildAction == IncrementalBuilder.PostBuildAction.UPDATE_CLASSPATH){
					updateBuildClasspath(jrefProject);
				} else if(postBuildAction == IncrementalBuilder.PostBuildAction.CLEAN_REBUILD) {
					if(JReFrameworkerPreferences.isVerboseLoggingEnabled()){
						Log.info("Rebuilding");
					}
					clean(monitor);
				}
			} catch (IncrementalBuilderException e) {
				Log.error("Error incrementally building JReFrameworker project", e);
			}
		}
	}
	if(JReFrameworkerPreferences.isVerboseLoggingEnabled()){
		Log.info("Incremental build complete");
	}
}
 
Example 8
Source File: IDEMultiPageReportEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * does when resource changed
 */
public void resourceChanged( IResourceChangeEvent event )
{
	IResourceDelta delta = event.getDelta( );
	try
	{
		if ( delta != null )
			delta.accept( this );
	}
	catch ( CoreException exception )
	{
		// What should be done here?
	}
}
 
Example 9
Source File: ResourcesWatcher.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	try {
		IResource resource = event.getResource();
		switch (event.getType()) {
		case IResourceChangeEvent.PRE_DELETE:
			if (resource != null) {
				switch (resource.getType()) {
				case IResource.PROJECT:
					// called when project is deleted.
					deleteProject((IProject) resource);
					break;
				}
			}
			break;
		case IResourceChangeEvent.PRE_CLOSE:
			if (resource != null) {
				switch (resource.getType()) {
				case IResource.PROJECT:
					// called when project is closed.
					closeProject((IProject) resource);
					break;
				}
			}
			break;
		case IResourceChangeEvent.POST_CHANGE:
			IResourceDelta delta = event.getDelta();
			if (delta != null) {
				delta.accept(this);
			}
			break;
		}
	} catch (Throwable e) {
		Trace.trace(Trace.SEVERE, "Error while TypeScript resource changed", e);
	}
}
 
Example 10
Source File: SizeControlContribution.java    From tlaplus with MIT License 5 votes vote down vote up
public void resourceChanged(final IResourceChangeEvent event) {
	final IResourceDelta delta = event.getDelta();
	if (delta != null) {
		try {
			// We cannot get the spec manager if it has not been
			// instantiated because this would trigger a resource change
			// event, and this code is being called within a resourceChanged
			// method. Such an infinite loop is not allowed.
			if (Activator.isSpecManagerInstantiated()) {
				// delta.accept calls the visit method of the
				// visitor on the delta.
				final ToolboxDirectoryVisitor toolboxDirectoryFinder = new ToolboxDirectoryVisitor();
				delta.accept(toolboxDirectoryFinder);
				final List<IProject> directories = toolboxDirectoryFinder.getDirectories();
				// Set resource to the IResource representing a
				// project for a spec. This resource is embodied in
				// the file system as the spec's .toolbox director.
				for (Iterator<IProject> it = directories.iterator(); it.hasNext();) {
					final IProject resource = it.next();
					final long specSize = ResourceHelper.getSizeOfJavaFileResource(resource);

					// TO-DO: If this is the currently opened spec,
					// change display of that spec's size.
					final Spec curSpec = ToolboxHandle.getCurrentSpec();
					if (curSpec != null) {
						curSpec.setSize(specSize);
						if (curSpec.getProject().equals(resource)) {
							updateSize(specSize);
						}
					}
				}
			}
		} catch (CoreException e) {
			Activator.getDefault().logError("Error during post save status update", e);
		}
	}
}
 
Example 11
Source File: FindBugs2Eclipse.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    if (event.getSource() instanceof IProject) {
        cleanClassClache((IProject) event.getSource());
    } else if (event.getResource() instanceof IProject) {
        cleanClassClache((IProject) event.getResource());
    } else if (event.getDelta() != null) {
        final Set<IProject> affectedProjects = new HashSet<>();
        final IResourceDelta delta = event.getDelta();
        try {
            delta.accept(new IResourceDeltaVisitor() {
                @Override
                public boolean visit(IResourceDelta d1) throws CoreException {
                    if (d1 == delta || d1.getFlags() == 0 || d1.getFlags() == IResourceDelta.MARKERS) {
                        return true;
                    }
                    IResource resource = d1.getResource();
                    if (resource instanceof IProject) {
                        affectedProjects.add((IProject) resource);
                        return false;
                    }
                    return true;
                }
            });
        } catch (CoreException e) {
            FindbugsPlugin.getDefault().logException(e, "Error traversing resource delta");
        }
        for (IProject iProject : affectedProjects) {
            cleanClassClache(iProject);
        }
    }
}
 
Example 12
Source File: DotGraphView.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	if (event.getType() != IResourceChangeEvent.POST_BUILD && event
			.getType() != IResourceChangeEvent.POST_CHANGE) {
		return;
	}
	IResourceDelta rootDelta = event.getDelta();
	try {
		rootDelta.accept(resourceVisitor);
	} catch (CoreException e) {
		DotActivatorEx.logError(e);
	}
}
 
Example 13
Source File: SharedResourcesManager.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private String deltaToString(IResourceDelta delta) {
  ToStringResourceDeltaVisitor visitor = new ToStringResourceDeltaVisitor();
  try {
    delta.accept(
        visitor,
        IContainer.INCLUDE_PHANTOMS
            | IContainer.INCLUDE_HIDDEN
            | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
  } catch (CoreException e) {
    log.error("ToStringResourceDelta visitor crashed", e);
    return "";
  }
  return visitor.toString();
}
 
Example 14
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
	try {
		IResourceDelta delta = event.getDelta();
		delta.accept(this);
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("failed to send diagnostics", e);
	}

}
 
Example 15
Source File: JavaHotCodeReplaceProvider.java    From java-debug with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the class file visitor after visiting the resource change. The
 * visitor contains the changed class files and qualified type names. Returns
 * <code>null</code> if the visitor encounters an exception, or the delta is not
 * a POST_BUILD.
 */
private ChangedClassFilesVisitor getChangedClassFiles(IResourceChangeEvent event) {
    IResourceDelta delta = event.getDelta();
    if (event.getType() != IResourceChangeEvent.POST_BUILD || delta == null) {
        return null;
    }
    classFilesVisitor.reset();
    try {
        delta.accept(classFilesVisitor);
    } catch (CoreException e) {
        return null; // quiet failure
    }
    return classFilesVisitor;
}
 
Example 16
Source File: ProblemMarkerManager.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(IResourceChangeEvent event) {
    HashSet<IResource> changedElements = new HashSet<IResource>();

    try {
        IResourceDelta delta = event.getDelta();
        if (delta != null) {
            delta.accept(new ProjectErrorVisitor(changedElements));
        }
    } catch (CoreException e) {
        Log.log(e);
    }

    if (!changedElements.isEmpty()) {
        boolean hasChanges = false;
        synchronized (this) {
            if (fResourcesWithMarkerChanges.isEmpty()) {
                fResourcesWithMarkerChanges = changedElements;
                hasChanges = true;
            } else {
                hasChanges = fResourcesWithMarkerChanges.addAll(changedElements);
            }
        }
        if (hasChanges) {
            fireChanges();
        }
    }
}
 
Example 17
Source File: TsvBuilder.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
	final ItemsXmlFinder finder = new ItemsXmlFinder();
	delta.accept(finder);
	checkTsv(finder.files, monitor);
}
 
Example 18
Source File: SCTBuilder.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
	delta.accept(new DeltaVisitor());
}
 
Example 19
Source File: Builder.java    From cppcheclipse with Apache License 2.0 4 votes vote down vote up
protected void incrementalBuild(IResourceDelta delta,
		IProgressMonitor monitor) throws CoreException {
	monitor.beginTask(Messages.Builder_IncrementalBuilderTask, delta
			.getAffectedChildren().length);
	delta.accept(new DeltaVisitor(monitor, delta));
}
 
Example 20
Source File: RadlBuilder.java    From RADL with Apache License 2.0 4 votes vote down vote up
private void incrementalBuild(IResourceDelta delta) throws CoreException {
  delta.accept(radlValidatingVisitor);
}