]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-before/core extension/org/eclipse/jdt/internal/corext/template/java/TypeVariableResolver.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / core extension / org / eclipse / jdt / internal / corext / template / java / TypeVariableResolver.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.core.Signature;
20
21import org.eclipse.jdt.internal.corext.template.java.CompilationUnitCompletion.Variable;
22
23import org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable;
24
25/**
26 * Resolves to the lower bound of a type argument of another template variable.
27 *
28 * @since 3.3
29 */
30public class TypeVariableResolver extends TemplateVariableResolver {
31
32 public TypeVariableResolver() {
33 }
34
35 /*
36 * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
37 * @since 3.3
38 */
39 @Override
40 public void resolve(TemplateVariable variable, TemplateContext context) {
41 if (!(variable instanceof MultiVariable)) {
42 super.resolve(variable, context);
43 return;
44 }
45 MultiVariable mv= (MultiVariable) variable;
46 List<String> params= variable.getVariableType().getParams();
47 if (params.isEmpty()) {
48 super.resolve(variable, context);
49 return;
50 }
51
52 JavaContext jc= (JavaContext) context;
53 String reference= params.get(0);
54 int index= 0;
55 if (params.size() > 1) {
56 String indexParam= params.get(1);
57 try {
58 index= Integer.parseInt(indexParam);
59 } catch (NumberFormatException x) {
60 }
61 }
62 TemplateVariable refVar= jc.getTemplateVariable(reference);
63 if (refVar instanceof JavaVariable) {
64 JavaVariable jvar= (JavaVariable) refVar;
65 resolve(mv, jvar, index, jc);
66
67 return;
68 }
69
70
71 super.resolve(variable, context);
72 }
73
74 private void resolve(MultiVariable mv, JavaVariable master, int index, JavaContext context) {
75 Object[] choices= master.getChoices();
76 if (choices instanceof Variable[]) {
77 context.addDependency(master, mv);
78 Variable[] variables= (Variable[]) choices;
79 String type= master.getParamType();
80 for (int i= 0; i < choices.length; i++) {
81 String[] bounds= variables[i].getTypeArgumentBoundSignatures(type, index);
82 for (int j= 0; j < bounds.length; j++)
83 bounds[j]= Signature.getSignatureSimpleName(bounds[j]);
84 mv.setChoices(variables[i], bounds);
85 }
86 mv.setKey(master.getCurrentChoice());
87 } else {
88 super.resolve(mv, context);
89 return;
90 }
91 }
92
93}