update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / template / macro / VariableTypeMacroBase.java
blob18864cb4003daef31a589e7100e0a4c8c30f447e
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.codeInsight.template.macro;
18 import com.intellij.codeInsight.lookup.LookupElement;
19 import com.intellij.codeInsight.template.*;
20 import com.intellij.codeInsight.template.impl.JavaTemplateUtil;
21 import com.intellij.psi.PsiElement;
22 import org.jetbrains.annotations.NotNull;
23 import org.jetbrains.annotations.Nullable;
25 import java.util.LinkedHashSet;
26 import java.util.Set;
28 /**
29 * @author ven
31 public abstract class VariableTypeMacroBase implements Macro {
32 @Nullable
33 protected abstract PsiElement[] getVariables(Expression[] params, final ExpressionContext context);
35 public LookupElement[] calculateLookupItems(@NotNull Expression[] params, final ExpressionContext context) {
36 final PsiElement[] vars = getVariables(params, context);
37 if (vars == null || vars.length < 2) return null;
38 Set<LookupElement> set = new LinkedHashSet<LookupElement>();
39 for (PsiElement element : vars) {
40 JavaTemplateUtil.addElementLookupItem(set, element);
42 return set.toArray(new LookupElement[set.size()]);
45 public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
46 final PsiElement[] vars = getVariables(params, context);
47 if (vars == null || vars.length == 0) return null;
48 return new JavaPsiElementResult(vars[0]);
51 public Result calculateQuickResult(@NotNull Expression[] params, ExpressionContext context) {
52 return null;
55 public String getDefaultValue() {
56 return "a";