KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > template > java > ElementTypeResolver


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.template.java;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.jface.text.templates.TemplateContext;
16 import org.eclipse.jface.text.templates.TemplateVariable;
17 import org.eclipse.jface.text.templates.TemplateVariableResolver;
18
19 import org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion.Variable;
20
21 import org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable;
22
23
24 public class ElementTypeResolver extends TemplateVariableResolver {
25
26     public ElementTypeResolver() {
27     }
28     
29     /*
30      * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
31      * @since 3.3
32      */

33     public void resolve(TemplateVariable variable, TemplateContext context) {
34         if (!(variable instanceof MultiVariable)) {
35             super.resolve(variable, context);
36             return;
37         }
38         MultiVariable mv= (MultiVariable) variable;
39         List JavaDoc params= variable.getVariableType().getParams();
40         if (params.isEmpty()) {
41             super.resolve(variable, context);
42             return;
43         }
44         
45         JavaContext jc= (JavaContext) context;
46         String JavaDoc reference= (String JavaDoc) params.get(0);
47         TemplateVariable refVar= jc.getTemplateVariable(reference);
48         if (refVar instanceof JavaVariable) {
49             JavaVariable jvar= (JavaVariable) refVar;
50             resolve(mv, jvar, jc);
51             return;
52         }
53         
54         super.resolve(variable, context);
55     }
56
57     private void resolve(MultiVariable variable, JavaVariable master, JavaContext context) {
58         Object JavaDoc[] choices= master.getChoices();
59         if (choices instanceof Variable[]) {
60             Variable[] variables= (Variable[]) choices;
61
62             for (int i= 0; i < variables.length; i++)
63                 variable.setChoices(variables[i], variables[i].getMemberTypeNames());
64
65             context.addDependency(master, variable);
66             variable.setKey(master.getCurrentChoice());
67         } else {
68             super.resolve(variable, context);
69         }
70     }
71 }
72
Popular Tags