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
;
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
34 public abstract class LookupElement
extends UserDataHolderBase
{
35 public static final LookupElement
[] EMPTY_ARRAY
= new LookupElement
[0];
36 private PrefixMatcher myPrefixMatcher
= PrefixMatcher
.FALSE_MATCHER
;
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);
55 public final PrefixMatcher
getPrefixMatcher() {
56 return myPrefixMatcher
;
60 public Object
getObject() {
64 public void handleInsert(InsertionContext context
) {
68 public String
toString() {
69 return getLookupString();
72 public void renderElement(LookupElementPresentation presentation
) {
73 presentation
.setItemText(getLookupString());
77 public <T
> T
as(Class
<T
> aClass
) {
78 //noinspection unchecked
79 return aClass
.isInstance(this) ?
(T
) this : null;