1 package net.sourceforge.phpeclipse.builder;
5 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
6 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
7 import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
8 import net.sourceforge.phpeclipse.resourcesview.PHPProject;
10 import org.eclipse.core.resources.IFile;
11 import org.eclipse.core.resources.IProject;
12 import org.eclipse.core.resources.IResource;
13 import org.eclipse.core.resources.IResourceDelta;
14 import org.eclipse.core.resources.IResourceVisitor;
15 import org.eclipse.core.resources.IncrementalProjectBuilder;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IConfigurationElement;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.OperationCanceledException;
22 * Builder for .php files.
25 * @see org.eclipse.core.resources.IncrementalProjectBuilder
26 * @see org.eclipse.core.resources.IResourceDelta
28 public class ParserBuilder extends IncrementalProjectBuilder {
29 private final static int TOTAL_WORK = 100;
34 public ParserBuilder() {
40 protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
41 monitor.beginTask("Parsing files", TOTAL_WORK);
43 if (kind == IncrementalProjectBuilder.FULL_BUILD) {
44 IResourceDelta delta = getDelta(getProject());
46 processFull(getProject(), monitor);
48 } else { // INCREMENTAL_BUILD or AUTO_BUILD
50 IResourceDelta delta = getDelta(getProject());
52 delta.accept(new ParserVisitor(getProject(), monitor));
61 * Performs a <code>FULL_BUILD</code> by visiting all nodes in the resource
62 * tree under the specified project.
66 public void processFull(final IProject iProject, final IProgressMonitor monitor) {
67 final IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(iProject);
68 // Create resource visitor logic
69 IResourceVisitor myVisitor = new IResourceVisitor() {
70 public boolean visit(IResource resource) throws CoreException {
71 if (resource.getType() == IResource.FILE) {
72 if (monitor.isCanceled()) {
73 throw new OperationCanceledException();
75 if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) {
77 monitor.subTask("Parsing: " + resource.getFullPath());
78 // check for parsing errors
79 PHPParserAction.parseFile((IFile) resource);
80 // update indexfile for the project:
81 PHPProject nature = (PHPProject) iProject.getNature(PHPeclipsePlugin.PHP_NATURE_ID);
82 indexManager.addFile((IFile) resource);
90 // Process the project using the visitor just created
93 // if (iProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
94 // thePHPProject = new PHPProject();
95 // thePHPProject.setProject(iProject);
97 indexManager.initialize();
98 iProject.accept(myVisitor);
99 indexManager.writeFile();
100 } catch (CoreException e) {
107 * Sets initialization data for this builder.
109 * This method is part of the <code>IExecutableExtension</code>
113 * Subclasses are free to extend this method to pick up
114 * initialization parameters from the plug-in plug-in manifest
115 * (<code>plugin.xml</code>) file,
116 * but should be sure to invoke this method on their superclass.
118 * For example, the following method looks for a boolean-valued
119 * parameter named "trace":
121 * public void setInitializationData(IConfigurationElement cfig,
122 * String propertyName, Object data)
123 * throws CoreException {
124 * super.setInitializationData(cfig, propertyName, data);
125 * if (data instanceof Hashtable) {
126 * Hashtable args = (Hashtable) data;
127 * String traceValue = (String) args.get("trace");
128 * TRACING = (traceValue!=null && traceValue.equals("true"));
134 public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
135 super.setInitializationData(config, propertyName, data);
140 * Informs this builder that it is being started by the build management
141 * infrastructure. By the time this method is run, the builder's project
142 * is available and <code>setInitializationData</code> has been called.
143 * The default implementation should be called by all overriding methods.
145 * @see #setInitializationData
147 protected void startupOnInitialize() {
148 // traceMsg("Parse Builder Initialize - startupOnInitialize()");
152 * Write trace statements.
153 * System.out.println with prefix tagging used for simplicity.
155 // private void traceMsg(String msg) {
156 // if (PHPeclipsePlugin.DEBUG | traceEnabled)
157 // System.out.println(