1 package net.sourceforge.phpeclipse.builder;
5 import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil;
6 import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
8 import org.eclipse.core.resources.IFile;
9 import org.eclipse.core.resources.IProject;
10 import org.eclipse.core.resources.IResource;
11 import org.eclipse.core.resources.IResourceDelta;
12 import org.eclipse.core.resources.IResourceVisitor;
13 import org.eclipse.core.resources.IncrementalProjectBuilder;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.OperationCanceledException;
20 * Builder for .php files.
23 * @see org.eclipse.core.resources.IncrementalProjectBuilder
24 * @see org.eclipse.core.resources.IResourceDelta
26 public class ParserBuilder extends IncrementalProjectBuilder {
27 private final static int TOTAL_WORK = 100;
32 public ParserBuilder() {
38 protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
39 throws CoreException {
40 monitor.beginTask("Parsing files", TOTAL_WORK);
42 if (kind == IncrementalProjectBuilder.FULL_BUILD) {
43 IResourceDelta delta = getDelta(getProject());
45 processFull(getProject(), monitor);
47 } else { // INCREMENTAL_BUILD or AUTO_BUILD
49 IResourceDelta delta = getDelta(getProject());
51 delta.accept(new ParserVisitor(monitor));
60 * Performs a <code>FULL_BUILD</code> by visiting all nodes in the resource
61 * tree under the specified project.
65 public void processFull(IProject iProject, final IProgressMonitor monitor) {
67 // Create resource visitor logic
68 IResourceVisitor myVisitor = new IResourceVisitor() {
69 public boolean visit(IResource resource) throws CoreException {
70 if (resource.getType() == IResource.FILE) {
71 if (monitor.isCanceled()) {
72 throw new OperationCanceledException();
74 if ((resource.getFileExtension() != null)
75 && PHPFileUtil.isPHPFile((IFile) resource)) {
77 monitor.subTask("Parsing: " + resource.getFullPath());
78 PHPParserAction.parseFile((IFile) resource);
86 // Process the project using the visitor just created
88 iProject.accept(myVisitor);
89 } catch (CoreException e) {
96 * Sets initialization data for this builder.
98 * This method is part of the <code>IExecutableExtension</code>
102 * Subclasses are free to extend this method to pick up
103 * initialization parameters from the plug-in plug-in manifest
104 * (<code>plugin.xml</code>) file,
105 * but should be sure to invoke this method on their superclass.
107 * For example, the following method looks for a boolean-valued
108 * parameter named "trace":
110 * public void setInitializationData(IConfigurationElement cfig,
111 * String propertyName, Object data)
112 * throws CoreException {
113 * super.setInitializationData(cfig, propertyName, data);
114 * if (data instanceof Hashtable) {
115 * Hashtable args = (Hashtable) data;
116 * String traceValue = (String) args.get("trace");
117 * TRACING = (traceValue!=null && traceValue.equals("true"));
123 public void setInitializationData(
124 IConfigurationElement config,
127 throws CoreException {
128 super.setInitializationData(config, propertyName, data);
133 * Informs this builder that it is being started by the build management
134 * infrastructure. By the time this method is run, the builder's project
135 * is available and <code>setInitializationData</code> has been called.
136 * The default implementation should be called by all overriding methods.
138 * @see #setInitializationData
140 protected void startupOnInitialize() {
141 // traceMsg("Parse Builder Initialize - startupOnInitialize()");
145 * Write trace statements.
146 * System.out.println with prefix tagging used for simplicity.
148 // private void traceMsg(String msg) {
149 // if (PHPeclipsePlugin.DEBUG | traceEnabled)
150 // System.out.println(