Syntax highlighting is changeable.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / corext / template / php / JavaContextType.java
1 /*******************************************************************************
2  * Copyright (c) 2000, orporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *     Sebastian Davids: sdavids@gmx.de - see bug 25376
11  *******************************************************************************/
12 package net.sourceforge.phpdt.internal.corext.template.php;
13
14 import net.sourceforge.phpdt.core.ICompilationUnit;
15 import net.sourceforge.phpdt.core.IJavaProject;
16 import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
17
18 import org.eclipse.jface.text.IDocument;
19 import org.eclipse.jface.text.templates.GlobalTemplateVariables;
20 import org.eclipse.jface.text.templates.TemplateContext;
21 import org.eclipse.jface.text.templates.TemplateVariableResolver;
22 //import net.sourceforge.phpdt.internal.ui.text.template.contentassist.*;
23 //import net.sourceforge.phpdt.internal.ui.text.template.contentassist.MultiVariableGuess;
24
25 /**
26  * A context type for java code.
27  */
28 public class JavaContextType extends CompilationUnitContextType {
29
30         public static final String NAME= "php"; //$NON-NLS-1$
31
32 //      protected static class Array extends TemplateVariableResolver {
33 //              public Array() {
34 //                      super("array", TemplateMessages.getString("JavaContextType.variable.description.array")); //$NON-NLS-1$ //$NON-NLS-2$
35 //              }
36 //              protected String[] resolveAll(TemplateContext context) {
37 //              return ((JavaContext) context).guessArrays();
38 //          }
39 //              /*
40 //               * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
41 //               */
42 //              public void resolve(TemplateVariable variable, TemplateContext context) {
43 //                      if (variable instanceof MultiVariable) {
44 //                              JavaContext jc= (JavaContext) context;
45 //                              MultiVariable mv= (MultiVariable) variable;
46 //                              String[] bindings= resolveAll(context);
47 //                              if (bindings.length > 0) {
48 //                                      mv.setValues(bindings);
49 //                                      MultiVariableGuess guess= jc.getMultiVariableGuess();
50 //                                      if (guess == null) {
51 //                                              guess= new MultiVariableGuess(mv);
52 //                                              jc.setMultiVariableGuess(guess);
53 //                                      }
54 //                              }
55 //                              if (bindings.length > 1)
56 //                                      variable.setUnambiguous(false);
57 //                              else
58 //                                      variable.setUnambiguous(isUnambiguous(context));
59 //                      } else
60 //                              super.resolve(variable, context);
61 //              }
62 //      }
63 //
64 //      protected static class ArrayType extends TemplateVariableResolver {
65 //          public ArrayType() {
66 //              super("array_type", TemplateMessages.getString("JavaContextType.variable.description.array.type")); //$NON-NLS-1$ //$NON-NLS-2$
67 //          }
68 //          protected String[] resolveAll(TemplateContext context) {
69 //              
70 //              String[] arrayTypes= ((JavaContext) context).guessArrayTypes();
71 //              if (arrayTypes != null)
72 //                      return arrayTypes;
73 //              else
74 //                      return super.resolveAll(context);
75 //          }
76 //          
77 //              /*
78 //               * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
79 //               */
80 //              public void resolve(TemplateVariable variable, TemplateContext context) {
81 //                      if (variable instanceof MultiVariable) {
82 //                              MultiVariable mv= (MultiVariable) variable;
83 //                              String[] arrays= ((JavaContext) context).guessArrays();
84 //                              String[][] types= ((JavaContext) context).guessGroupedArrayTypes();
85 //                              
86 //                              for (int i= 0; i < arrays.length; i++) {
87 //                                      mv.setValues(arrays[i], types[i]);
88 //                              }
89 //
90 //                              if (arrays.length > 1 || types.length == 1 && types[0].length > 1)
91 //                                      variable.setUnambiguous(false);
92 //                              else
93 //                                      variable.setUnambiguous(isUnambiguous(context));
94 //                              
95 //                      } else
96 //                              super.resolve(variable, context);
97 //              }
98 //      }
99 //
100 //      protected static class ArrayElement extends TemplateVariableResolver {
101 //          public ArrayElement() {
102 //              super("array_element", TemplateMessages.getString("JavaContextType.variable.description.array.element"));       //$NON-NLS-1$ //$NON-NLS-2$    
103 //          }
104 //          protected String[] resolveAll(TemplateContext context) {
105 //              return ((JavaContext) context).guessArrayElements();
106 //          }       
107 //
108 //              /*
109 //               * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
110 //               */
111 //              public void resolve(TemplateVariable variable, TemplateContext context) {
112 //                      if (variable instanceof MultiVariable) {
113 //                              MultiVariable mv= (MultiVariable) variable;
114 //                              String[] arrays= ((JavaContext) context).guessArrays();
115 //                              String[][] elems= ((JavaContext) context).guessGroupedArrayElements();
116 //                              
117 //                              for (int i= 0; i < arrays.length; i++) {
118 //                                      mv.setValues(arrays[i], elems[i]);
119 //                              }
120 //
121 //                              if (arrays.length > 1 || elems.length == 1 && elems[0].length > 1)
122 //                                      variable.setUnambiguous(false);
123 //                              else
124 //                                      variable.setUnambiguous(isUnambiguous(context));
125 //                              
126 //                      } else
127 //                              super.resolve(variable, context);
128 //              }
129 //      }
130 //
131 //      protected static class Index extends TemplateVariableResolver {
132 //          public Index() {
133 //              super("index", TemplateMessages.getString("JavaContextType.variable.description.index")); //$NON-NLS-1$ //$NON-NLS-2$
134 //          }
135 //          protected String resolve(TemplateContext context) {
136 //              return ((JavaContext) context).getIndex();
137 //          }       
138 //      }
139 //
140 //      protected static class Collection extends TemplateVariableResolver {
141 //          public Collection() {
142 //                  super("collection", TemplateMessages.getString("JavaContextType.variable.description.collection")); //$NON-NLS-1$ //$NON-NLS-2$
143 //              }
144 //          
145 //              protected String[] resolveAll(TemplateContext context) {
146 //              String[] collections= ((JavaContext) context).guessCollections();
147 //              if (collections.length > 0)
148 //                      return collections;
149 //              else
150 //                      return super.resolveAll(context);
151 //              }
152 //      }
153 //
154 //      protected static class Iterator extends TemplateVariableResolver {
155 //
156 //          public Iterator() {
157 //                  super("iterator", TemplateMessages.getString("JavaContextType.variable.description.iterator")); //$NON-NLS-1$ //$NON-NLS-2$
158 //              }
159 //          protected String resolve(TemplateContext context) {
160 //              JavaContext javaContext= (JavaContext) context;
161 //
162 //                      if (!context.isReadOnly())
163 //                      javaContext.addIteratorImport();
164 //              
165 //              return javaContext.getIterator();
166 //          }       
167 //      }
168 //      
169         protected static class Todo extends TemplateVariableResolver {
170
171                 public Todo() {
172                         super("todo", JavaTemplateMessages.getString("JavaContextType.variable.description.todo")); //$NON-NLS-1$ //$NON-NLS-2$
173                 }
174                 protected String resolve(TemplateContext context) {
175                         JavaContext javaContext= (JavaContext) context;
176                         ICompilationUnit compilationUnit= javaContext.getCompilationUnit();
177                         if (compilationUnit == null)
178                                 return "XXX"; //$NON-NLS-1$
179                         
180                         IJavaProject javaProject= compilationUnit.getJavaProject();
181                         String todoTaskTag= StubUtility.getTodoTaskTag(javaProject);
182                         if (todoTaskTag == null)
183                                 return "XXX"; //$NON-NLS-1$
184
185                         return todoTaskTag;
186                 }
187         }       
188 /*
189         protected static class Arguments extends SimpleVariableResolver {
190             public Arguments() {
191                 super("arguments", TemplateMessages.getString("JavaContextType.variable.description.arguments"), "");   
192             }
193         }
194 */      
195
196
197         /**
198          * Creates a java context type.
199          */
200         public JavaContextType() {
201                 super(NAME);
202                 
203                 // global
204                 addResolver(new GlobalTemplateVariables.Cursor());
205                 addResolver(new GlobalTemplateVariables.WordSelection());
206                 addResolver(new GlobalTemplateVariables.LineSelection());
207                 addResolver(new GlobalTemplateVariables.Dollar());
208                 addResolver(new GlobalTemplateVariables.Date());
209                 addResolver(new GlobalTemplateVariables.Year());
210                 addResolver(new GlobalTemplateVariables.Time());
211                 addResolver(new GlobalTemplateVariables.User());
212                 
213                 // compilation unit
214                 addResolver(new File());
215                 addResolver(new PrimaryTypeName());
216                 addResolver(new ReturnType());
217                 addResolver(new Method());
218                 addResolver(new Type());
219                 addResolver(new Package());
220                 addResolver(new Project());
221                 addResolver(new Arguments());
222
223                 // java
224 //              addResolver(new Array());
225 //              addResolver(new ArrayType());
226 //              addResolver(new ArrayElement());
227 //              addResolver(new Index());
228 //              addResolver(new Iterator());
229 //              addResolver(new Collection());
230                 addResolver(new Todo());
231         }
232         
233
234         /* (non-Javadoc)
235          * @see net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument, int, int, net.sourceforge.phpdt.core.ICompilationUnit)
236          */
237         public CompilationUnitContext createContext(IDocument document, int offset, int length, ICompilationUnit compilationUnit) {
238                 return new JavaContext(this, document, offset, length, compilationUnit);
239         }
240
241 }