a bugfix on variables
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / externaltools / variable / ExpandVariableContext.java
1 package net.sourceforge.phpdt.externaltools.variable;
2
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
8  
9 Contributors:
10 **********************************************************************/
11
12 import org.eclipse.core.resources.IProject;
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.resources.IncrementalProjectBuilder;
15 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
16
17 /**
18  * Represents the context the external tool is running in
19  * that a variable uses to expand itself.
20  */
21 public final class ExpandVariableContext {
22         public static final ExpandVariableContext EMPTY_CONTEXT = new ExpandVariableContext(null);
23         
24         private IProject project = null;
25         private IResource selectedResource = null;
26         private String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
27         
28         /**
29          * Create a context for an external tool running
30          * as a builder on the given project.
31          * 
32          * @param project the <code>IProject</code> being built.
33          * @param buildKind the kind of build being performed
34          *              (see <code>IncrementalProjectBuilder</code>).
35          */
36         public ExpandVariableContext(IProject project, int buildKind) {
37                 super();
38                 this.project = project;
39                 switch (buildKind) {
40                         case IncrementalProjectBuilder.INCREMENTAL_BUILD :
41                                 this.buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
42                                 break;
43                         case IncrementalProjectBuilder.FULL_BUILD :
44                                 this.buildType = IExternalToolConstants.BUILD_TYPE_FULL;
45                                 break;
46                         case IncrementalProjectBuilder.AUTO_BUILD :
47                                 this.buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
48                                 break;
49                         default :
50                                 this.buildType = IExternalToolConstants.BUILD_TYPE_NONE;
51                                 break;
52                 }
53         }
54         
55         /**
56          * Create a context for an external tool running
57          * with the given resource selected.
58          * 
59          * @param selectedResource the <code>IResource</code> selected
60          *              or <code>null</code> if none.
61          */
62         public ExpandVariableContext(IResource selectedResource) {
63                 super();
64                 if (selectedResource != null) {
65                         this.selectedResource = selectedResource;
66                         this.project = selectedResource.getProject();
67                 }
68         }
69         
70         /**
71          * Returns the build type being performed if the
72          * external tool is being run as a project builder.
73          * 
74          * @return one of the <code>IExternalToolConstants.BUILD_TYPE_*</code> constants.
75          */
76         public String getBuildType() {
77                 return buildType;
78         }
79         
80         /**
81          * Returns the project which the variable can use. This
82          * will the the project being built if the tool is being
83          * run as a builder. Otherwise, it is the project of the
84          * selected resource, or <code>null</code> if none.
85          * 
86          * @return the <code>IProject</code> or <code>null</code> if none
87          */
88         public IProject getProject() {
89                 return project;
90         }
91         
92         /**
93          * Returns the resource selected at the time the tool
94          * is run, or <code>null</code> if none selected.
95          * 
96          * @return the <code>IResource</code> selected, or <code>null</code> if none
97          */
98         public IResource getSelectedResource() {
99                 return selectedResource;
100         }
101 }