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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.template.java;
13 import java.util.Iterator;
14 import java.util.List;
16 import org.eclipse.jface.text.templates.TemplateContext;
17 import org.eclipse.jface.text.templates.TemplateVariable;
18 import org.eclipse.jface.text.templates.TemplateVariableResolver;
21 * Resolver for the <code>link</code> variable. Resolves to a
22 * first parameter puts the value into linked mode. Shows proposals
27 public class LinkResolver extends TemplateVariableResolver {
29 private String[] fProposals;
31 public LinkResolver(String type, String description) {
32 super(type, description);
36 * Default ctor for instantiation by the extension point.
38 public LinkResolver() {
42 * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
45 public void resolve(TemplateVariable variable, TemplateContext context) {
47 variable.setUnambiguous(false);
49 if (variable instanceof JavaVariable) {
50 JavaContext jc= (JavaContext) context;
51 JavaVariable jv= (JavaVariable) variable;
53 List<String> params= variable.getVariableType().getParams();
54 if (params.size() > 0) {
55 fProposals= new String[params.size()];
57 for (Iterator<String> iterator= params.iterator(); iterator.hasNext();) {
58 String param= iterator.next();
62 jv.setChoices(fProposals);
63 jv.setCurrentChoice(fProposals[0]);
65 jc.markAsUsed(jv.getDefaultValue());
67 fProposals= new String[] { variable.getDefaultValue() };
68 super.resolve(variable, context);
72 super.resolve(variable, context);
76 * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolveAll(org.eclipse.jface.text.templates.TemplateContext)
79 protected String[] resolveAll(TemplateContext context) {