]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/core extension/org/eclipse/jdt/internal/corext/template/java/ElementTypeResolver.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / core extension / org / eclipse / jdt / internal / corext / template / java / ElementTypeResolver.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2005, 2011 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 *******************************************************************************/
11package org.eclipse.jdt.internal.corext.template.java;
12
13import java.util.List;
14
15import org.eclipse.jface.text.templates.TemplateContext;
16import org.eclipse.jface.text.templates.TemplateVariable;
17import org.eclipse.jface.text.templates.TemplateVariableResolver;
18
19import org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion.Variable;
20
21import org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable;
22
23
24public 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 @Override
34 public void resolve(TemplateVariable variable, TemplateContext context) {
35 if (!(variable instanceof MultiVariable)) {
36 super.resolve(variable, context);
37 return;
38 }
39 MultiVariable mv= (MultiVariable) variable;
40 List<String> params= variable.getVariableType().getParams();
41 if (params.isEmpty()) {
42 super.resolve(variable, context);
43 return;
44 }
45
46 JavaContext jc= (JavaContext) context;
47 String reference= params.get(0);
48 TemplateVariable refVar= jc.getTemplateVariable(reference);
49 if (refVar instanceof JavaVariable) {
50 JavaVariable jvar= (JavaVariable) refVar;
51 resolve(mv, jvar, jc);
52 return;
53 }
54
55 super.resolve(variable, context);
56 }
57
58 private void resolve(MultiVariable variable, JavaVariable master, JavaContext context) {
59 Object[] choices= master.getChoices();
60 if (choices instanceof Variable[]) {
61 Variable[] variables= (Variable[]) choices;
62
63 for (int i= 0; i < variables.length; i++)
64 variable.setChoices(variables[i], variables[i].getMemberTypeNames());
65
66 context.addDependency(master, variable);
67 variable.setKey(master.getCurrentChoice());
68 } else {
69 super.resolve(variable, context);
70 }
71 }
72}