AutoCompletionPolicy removed from LookupElement, an ability to customize auto-complet...
[fedora-idea.git] / platform / lang-api / src / com / intellij / codeInsight / lookup / LookupElement.java
blob9df0c21e544c56d9ccc151de816667de6a43bdc6
1 /*
2 * Copyright 2000-2007 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.lookup;
18 import com.intellij.codeInsight.completion.InsertionContext;
19 import com.intellij.codeInsight.completion.PrefixMatcher;
20 import com.intellij.openapi.util.UserDataHolderBase;
21 import org.jetbrains.annotations.NotNull;
22 import org.jetbrains.annotations.Nullable;
24 import java.util.Collections;
25 import java.util.Set;
27 /**
28 * A typical way to create lookup element is to use {@link com.intellij.codeInsight.lookup.LookupElementBuilder}.
29 * Another way is to subclass it. Use the latter way only if you need it to implement some additional interface, to modify equals/hashCode
30 * or other advanced logic
32 * @author peter
34 public abstract class LookupElement extends UserDataHolderBase {
35 public static final LookupElement[] EMPTY_ARRAY = new LookupElement[0];
36 private PrefixMatcher myPrefixMatcher = PrefixMatcher.FALSE_MATCHER;
38 @NotNull
39 public abstract String getLookupString();
41 public Set<String> getAllLookupStrings() {
42 return Collections.singleton(getLookupString());
45 public boolean setPrefixMatcher(@NotNull final PrefixMatcher matcher) {
46 myPrefixMatcher = matcher;
47 return isPrefixMatched();
50 public final boolean isPrefixMatched() {
51 return myPrefixMatcher.prefixMatches(this);
54 @NotNull
55 public final PrefixMatcher getPrefixMatcher() {
56 return myPrefixMatcher;
59 @NotNull
60 public Object getObject() {
61 return this;
64 public void handleInsert(InsertionContext context) {
67 @Override
68 public String toString() {
69 return getLookupString();
72 public void renderElement(LookupElementPresentation presentation) {
73 presentation.setItemText(getLookupString());
76 @Nullable
77 public <T> T as(Class<T> aClass) {
78 //noinspection unchecked
79 return aClass.isInstance(this) ? (T) this : null;