1 package net.sourceforge.phpdt.externaltools.variable;
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
10 **********************************************************************/
12 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.resources.IncrementalProjectBuilder;
19 * Represents the context the external tool is running in
20 * that a variable uses to expand itself.
22 public final class ExpandVariableContext {
23 public static final ExpandVariableContext EMPTY_CONTEXT = new ExpandVariableContext(null);
25 private IProject project = null;
26 private IResource selectedResource = null;
27 private String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
30 * Create a context for an external tool running
31 * as a builder on the given project.
33 * @param project the <code>IProject</code> being built.
34 * @param buildKind the kind of build being performed
35 * (see <code>IncrementalProjectBuilder</code>).
37 public ExpandVariableContext(IProject project, int buildKind) {
39 this.project = project;
41 case IncrementalProjectBuilder.INCREMENTAL_BUILD :
42 this.buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
44 case IncrementalProjectBuilder.FULL_BUILD :
45 this.buildType = IExternalToolConstants.BUILD_TYPE_FULL;
47 case IncrementalProjectBuilder.AUTO_BUILD :
48 this.buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
51 this.buildType = IExternalToolConstants.BUILD_TYPE_NONE;
57 * Create a context for an external tool running
58 * with the given resource selected.
60 * @param selectedResource the <code>IResource</code> selected
61 * or <code>null</code> if none.
63 public ExpandVariableContext(IResource selectedResource) {
65 if (selectedResource != null) {
66 this.selectedResource = selectedResource;
67 this.project = selectedResource.getProject();
72 * Returns the build type being performed if the
73 * external tool is being run as a project builder.
75 * @return one of the <code>IExternalToolConstants.BUILD_TYPE_*</code> constants.
77 public String getBuildType() {
82 * Returns the project which the variable can use. This
83 * will the the project being built if the tool is being
84 * run as a builder. Otherwise, it is the project of the
85 * selected resource, or <code>null</code> if none.
87 * @return the <code>IProject</code> or <code>null</code> if none
89 public IProject getProject() {
94 * Returns the resource selected at the time the tool
95 * is run, or <code>null</code> if none selected.
97 * @return the <code>IResource</code> selected, or <code>null</code> if none
99 public IResource getSelectedResource() {
100 return selectedResource;