2
* Created on 11/09/2005
4
package org.python.pydev.builder;
6
import org.eclipse.core.resources.IProject;
7
import org.eclipse.core.resources.IResource;
8
import org.eclipse.core.resources.IResourceDelta;
9
import org.eclipse.core.resources.IResourceDeltaVisitor;
10
import org.eclipse.core.runtime.CoreException;
11
import org.eclipse.core.runtime.IProgressMonitor;
12
import org.python.pydev.builder.pycremover.PycRemoverBuilderVisitor;
13
import org.python.pydev.core.REF;
14
import org.python.pydev.core.log.Log;
15
import org.python.pydev.editor.codecompletion.revisited.PythonPathHelper;
16
import org.python.pydev.plugin.nature.PythonNature;
18
public abstract class PydevInternalResourceDeltaVisitor extends PyDevBuilderVisitor implements IResourceDeltaVisitor{
20
PydevInternalResourceDeltaVisitor(IProgressMonitor monitor, int totalResources){
21
this.monitor = monitor;
22
this.totalResources = totalResources;
25
//variables used to communicate the progress
27
* this monitor might be set externally so that we can comunicate the progress to the user
30
public IProgressMonitor monitor;
32
* number of total resources to be visited (only used when the monitor is set)
35
public int totalResources;
37
* number of resources visited to the moment
38
* (updated in this class)
40
public int currentResourcesVisited = 0;
41
//end variables used to communicate the progress
44
* Visits the resource delta tree determining which files to rebuild (*.py).
46
* Subclasses should only reimplement visitChanged, visitAdded and visitRemoved. This method will not be called
47
* in the structure provided by pydev.
49
* @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
51
public boolean visit(IResourceDelta delta) throws CoreException {
56
IResource resource = delta.getResource();
62
int type = resource.getType();
65
//related bug https://sourceforge.net/tracker/index.php?func=detail&aid=1238850&group_id=85796&atid=577329
67
//the team-support plugins of eclipse use the IResource
68
//method setTeamPrivateMember to indicate resources
69
//that are only in the project for the team-stuff (e.g. .svn or
70
//.cvs or _darcs directories).
71
if (resource.isTeamPrivateMember()){
75
if (type == IResource.FOLDER) {
76
switch (delta.getKind()) {
77
case IResourceDelta.REMOVED:
78
visitRemovedResource(resource, null, monitor);
80
//for folders, we don't have to do anything if added or changed (we just treat their children, that should
81
//resolve for modules -- we do, however have to treat __init__.py differently).
86
if (type == IResource.FILE) {
87
String ext = resource.getFileExtension();
88
if(ext == null){ //resource.getFileExtension() may return null if it has none.
92
//only analyze projects with the python nature...
93
IProject project = resource.getProject();
94
PythonNature nature = PythonNature.getPythonNature(project);
96
if(project != null && nature != null){
97
//we just want to make the visit if it is a valid python file and it is in the pythonpath
98
if (PythonPathHelper.isValidSourceFile("."+ext)) {
100
boolean isAddOrChange = false;
101
isAddOrChange = chooseVisit(delta, resource, isAddOrChange);
104
//communicate the progress
105
currentResourcesVisited++;
106
PyDevBuilder.communicateProgress(monitor, totalResources, currentResourcesVisited, resource, this);
108
}else if(ext.equals("pyc")){
110
//we do that because we may have an added .pyc without a correspondent .py file
111
new PycRemoverBuilderVisitor().visitAddedResource(resource, null, monitor); //doc is not used in pyc remover
112
} catch (Exception e) {
123
protected boolean chooseVisit(IResourceDelta delta, IResource resource, boolean isAddOrChange) {
124
switch (delta.getKind()) {
125
case IResourceDelta.ADDED :
126
visitAddedResource(resource, REF.getDocFromResource(resource), monitor);
127
isAddOrChange = true;
129
case IResourceDelta.CHANGED:
130
visitChangedResource(resource, REF.getDocFromResource(resource), monitor);
131
isAddOrChange = true;
133
case IResourceDelta.REMOVED:
134
visitRemovedResource(resource, null, monitor);
137
return isAddOrChange;