01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.template.java;
11:
12: import java.util.Iterator;
13:
14: import org.eclipse.jface.text.IDocument;
15: import org.eclipse.jface.text.Position;
16: import org.eclipse.jface.text.templates.TemplateContextType;
17: import org.eclipse.jface.text.templates.TemplateVariableResolver;
18:
19: import org.eclipse.jdt.core.ICompilationUnit;
20:
21: /**
22: * The context type for templates inside SWT code.
23: *
24: * @since 3.4
25: */
26: public class SWTContextType extends CompilationUnitContextType {
27:
28: /**
29: * The id under which this context type is registered.
30: */
31: public static final String ID = "swt"; //$NON-NLS-1$
32:
33: public SWTContextType() {
34: }
35:
36: /* (non-Javadoc)
37: * @see org.eclipse.jdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument, int, int, org.eclipse.jdt.core.ICompilationUnit)
38: */
39: public CompilationUnitContext createContext(IDocument document,
40: int offset, int length, ICompilationUnit compilationUnit) {
41: return new JavaContext(this , document, offset, length,
42: compilationUnit);
43: }
44:
45: /* (non-Javadoc)
46: * @see org.eclipse.jdt.internal.corext.template.java.CompilationUnitContextType#createContext(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.Position, org.eclipse.jdt.core.ICompilationUnit)
47: */
48: public CompilationUnitContext createContext(IDocument document,
49: Position offset, ICompilationUnit compilationUnit) {
50: return new JavaContext(this , document, offset, compilationUnit);
51: }
52:
53: /**
54: * Inherit all resolvers from <code>otherContext</code>.
55: *
56: * @param otherContext the context from which to retrieve the resolvers from
57: */
58: public void inheritResolvers(TemplateContextType otherContext) {
59: for (Iterator iterator = otherContext.resolvers(); iterator
60: .hasNext();) {
61: TemplateVariableResolver resolver = (TemplateVariableResolver) iterator
62: .next();
63: addResolver(resolver);
64: }
65: }
66: }
|