IDEA-79862 Java: auto-insert space after completing "extends" and "implements"
[idea/community.git] / java / java-impl / src / com / intellij / codeInsight / completion / Java15CompletionData.java
1 /*
2  * Copyright 2000-2009 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.intellij.codeInsight.completion;
17
18 import com.intellij.codeInsight.TailType;
19 import com.intellij.psi.*;
20 import com.intellij.psi.filters.*;
21 import com.intellij.psi.filters.position.LeftNeighbour;
22 import com.intellij.psi.filters.position.SuperParentFilter;
23
24 /**
25  * @author ven
26  */
27 public class Java15CompletionData extends JavaCompletionData {
28
29   protected void initVariantsInFileScope() {
30     super.initVariantsInFileScope();
31     //static keyword in static import
32     {
33       final CompletionVariant variant = new CompletionVariant(PsiImportList.class, new LeftNeighbour(new TextFilter (PsiKeyword.IMPORT)));
34       variant.addCompletion(PsiKeyword.STATIC, TailType.HUMBLE_SPACE_BEFORE_WORD);
35
36       registerVariant(variant);
37     }
38
39     {
40       final ElementFilter position = new AndFilter(new LeftNeighbour(new TextFilter("@")),
41                                                    new NotFilter(new SuperParentFilter(
42                                                      new OrFilter(new ClassFilter(PsiNameValuePair.class),
43                                                          new ClassFilter(PsiParameterList.class))))
44                                                    );
45
46       final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, position);
47       variant.includeScopeClass(PsiClass.class);
48
49       variant.addCompletion(PsiKeyword.INTERFACE, TailType.HUMBLE_SPACE_BEFORE_WORD);
50
51       registerVariant(variant);
52     }
53
54     {
55       final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, CLASS_START);
56       variant.includeScopeClass(PsiClass.class);
57
58       variant.addCompletion(PsiKeyword.ENUM, TailType.HUMBLE_SPACE_BEFORE_WORD);
59       registerVariant(variant);
60     }
61
62   }
63
64   protected void initVariantsInClassScope() {
65     super.initVariantsInClassScope();
66     {
67       //Completion of "extends" & "super" inside wildcards
68       final CompletionVariant variant = new CompletionVariant(JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN);
69       variant.includeScopeClass(PsiVariable.class, true);
70       variant.includeScopeClass(PsiExpressionStatement.class, true);
71       variant.addCompletion(PsiKeyword.SUPER, TailType.HUMBLE_SPACE_BEFORE_WORD);
72       variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE_BEFORE_WORD);
73       registerVariant(variant);
74     }
75   }
76 }