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