]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/core extension/org/eclipse/jdt/internal/corext/template/java/LinkResolver.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / core extension / org / eclipse / jdt / internal / corext / template / java / LinkResolver.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 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  *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.template.java;
12
13 import java.util.Iterator;
14 import java.util.List;
15
16 import org.eclipse.jface.text.templates.TemplateContext;
17 import org.eclipse.jface.text.templates.TemplateVariable;
18 import org.eclipse.jface.text.templates.TemplateVariableResolver;
19
20 /**
21  * Resolver for the <code>link</code> variable. Resolves to a
22  * first parameter puts the value into linked mode. Shows proposals
23  * for each parameter.
24  *
25  * @since 3.4
26  */
27 public class LinkResolver extends TemplateVariableResolver {
28
29         private String[] fProposals;
30
31         public LinkResolver(String type, String description) {
32                 super(type, description);
33         }
34
35         /**
36          * Default ctor for instantiation by the extension point.
37          */
38         public LinkResolver() {
39         }
40
41         /* (non-Javadoc)
42          * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
43          */
44         @Override
45         public void resolve(TemplateVariable variable, TemplateContext context) {
46
47                 variable.setUnambiguous(false);
48
49                 if (variable instanceof JavaVariable) {
50                         JavaContext jc= (JavaContext) context;
51                         JavaVariable jv= (JavaVariable) variable;
52
53                         List<String> params= variable.getVariableType().getParams();
54                         if (params.size() > 0) {
55                                 fProposals= new String[params.size()];
56                                 int i= 0;
57                                 for (Iterator<String> iterator= params.iterator(); iterator.hasNext();) {
58                                         String param= iterator.next();
59                                         fProposals[i]= param;
60                                         i++;
61                                 }
62                                 jv.setChoices(fProposals);
63                                 jv.setCurrentChoice(fProposals[0]);
64
65                                 jc.markAsUsed(jv.getDefaultValue());
66                         } else {
67                                 fProposals= new String[] { variable.getDefaultValue() };
68                                 super.resolve(variable, context);
69                                 return;
70                         }
71                 } else
72                         super.resolve(variable, context);
73         }
74
75         /* (non-Javadoc)
76          * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolveAll(org.eclipse.jface.text.templates.TemplateContext)
77          */
78         @Override
79         protected String[] resolveAll(TemplateContext context) {
80                 return fProposals;
81         }
82 }