]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/core extension/org/eclipse/jdt/internal/corext/template/java/StaticImportResolver.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / core extension / org / eclipse / jdt / internal / corext / template / java / StaticImportResolver.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  *  Variable resolver for variable <code>importStatic</code>. Resolves to
22  *  static import statements.
23  *
24  *  @since 3.4
25  */
26 public class StaticImportResolver extends TemplateVariableResolver {
27
28         public StaticImportResolver(String type, String description) {
29                 super(type, description);
30         }
31
32         /**
33          * Default ctor for instantiation by the extension point.
34          */
35         public StaticImportResolver() {
36         }
37
38         /* (non-Javadoc)
39          * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
40          */
41         @Override
42         public void resolve(TemplateVariable variable, TemplateContext context) {
43                 variable.setUnambiguous(true);
44                 variable.setValue(""); //$NON-NLS-1$
45
46                 if (context instanceof JavaContext) {
47                         JavaContext jc= (JavaContext) context;
48                         List<String> params= variable.getVariableType().getParams();
49                         if (params.size() > 0) {
50                                 for (Iterator<String> iterator= params.iterator(); iterator.hasNext();) {
51                                         String qualifiedMemberName= iterator.next();
52                                         jc.addStaticImport(qualifiedMemberName);
53                                 }
54                         }
55                 } else {
56                         super.resolve(variable, context);
57                 }
58         }
59
60         /* (non-Javadoc)
61          * @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolveAll(org.eclipse.jface.text.templates.TemplateContext)
62          */
63         @Override
64         protected String[] resolveAll(TemplateContext context) {
65                 return new String[0];
66         }
67
68 }