a5ee3d495cd49b6007cc064556df3a00e81c42ae
[phpeclipse.git] /
1 /*
2  * (c) Copyright IBM Corp. 2000, 2001.
3  * All Rights Reserved.
4  */
5 package net.sourceforge.phpdt.internal.corext.template.php;
6
7 //import net.sourceforge.phpdt.core.ICompilationUnit;
8
9 import net.sourceforge.phpdt.core.ICompilationUnit;
10 import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType.File;
11
12 import org.eclipse.jface.text.IDocument;
13 import org.eclipse.jface.text.templates.GlobalTemplateVariables;
14 import org.eclipse.jface.text.templates.TemplateException;
15 import org.eclipse.jface.text.templates.TemplateVariable;
16
17 /**
18  * A context type for javadoc.
19  */ 
20 public class HTMLContextType extends CompilationUnitContextType {
21
22         /**
23          * Creates a java context type.
24          */
25         public HTMLContextType() {
26                 super("html"); //$NON-NLS-1$
27                 
28                 // global
29                 addResolver(new GlobalTemplateVariables.Cursor());
30                 addResolver(new GlobalTemplateVariables.WordSelection());
31                 addResolver(new GlobalTemplateVariables.LineSelection());
32                 addResolver(new GlobalTemplateVariables.Dollar());
33                 addResolver(new GlobalTemplateVariables.Date());
34                 addResolver(new GlobalTemplateVariables.Year());
35                 addResolver(new GlobalTemplateVariables.Time());
36                 addResolver(new GlobalTemplateVariables.User());
37                 
38                 addResolver(new File());
39         }
40         
41         /*
42          * @see ContextType#createContext()
43          */     
44         public CompilationUnitContext createContext(IDocument document, int offset, int length, ICompilationUnit compilationUnit) {
45                         return new HTMLUnitContext(this, document, offset, length, compilationUnit); 
46         }
47         /* (non-Javadoc)
48          * @see net.sourceforge.phpdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument, int, int, net.sourceforge.phpdt.core.ICompilationUnit)
49          */
50 //      public CompilationUnitContext createContext(IDocument document, int offset, int length, ICompilationUnit compilationUnit) {
51 //              return new JavaDocContext(this, document, offset, length, compilationUnit);
52 //      }
53         /* (non-Javadoc)
54          * @see net.sourceforge.phpdt.internal.corext.template.ContextType#validateVariables(net.sourceforge.phpdt.internal.corext.template.TemplateVariable[])
55          */
56         protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
57                 // check for multiple cursor variables          
58                 for (int i= 0; i < variables.length; i++) {
59                         TemplateVariable var= variables[i];
60                         if (var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) {
61                                 if (var.getOffsets().length > 1) {
62                                         throw new TemplateException(JavaTemplateMessages.getString("ContextType.error.multiple.cursor.variables")); //$NON-NLS-1$
63                                 }
64                         }
65                 }
66         }
67 }