/* * Copyright 2011 The authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.intellij.lang.ognl.completion; import com.intellij.codeInsight.completion.*; import com.intellij.codeInsight.lookup.LookupElementBuilder; import com.intellij.lang.ognl.psi.OgnlStringLiteral; import com.intellij.lang.ognl.psi.OgnlVariableExpression; import com.intellij.openapi.project.DumbAware; import com.intellij.patterns.PsiElementPattern; import com.intellij.psi.PsiElement; import com.intellij.util.ProcessingContext; import org.jetbrains.annotations.NotNull; import static com.intellij.lang.ognl.psi.OgnlKeyword.*; import static com.intellij.patterns.PlatformPatterns.psiElement; import static com.intellij.patterns.StandardPatterns.not; import static com.intellij.patterns.StandardPatterns.or; /** * @author Yann Cébron */ public class OgnlKeywordCompletionContributor extends CompletionContributor implements DumbAware { private static final String[] ALL = new String[]{ SHL, SHR, USHR, AND, BAND, OR, BOR, XOR, EQ, NEQ, LT, LTE, GT, GTE, NOT_IN, IN, NEW, TRUE, FALSE, NULL, INSTANCEOF }; private static final PsiElementPattern.Capture<PsiElement> STRING_LITERAL = psiElement().inside(OgnlStringLiteral.class); private static final PsiElementPattern.Capture<PsiElement> VARIABLE_EXPRESSION = psiElement().inside(OgnlVariableExpression.class); public OgnlKeywordCompletionContributor() { extend(CompletionType.BASIC, not(or(STRING_LITERAL, VARIABLE_EXPRESSION)), new CompletionProvider<CompletionParameters>() { @Override protected void addCompletions(@NotNull final CompletionParameters completionParameters, final ProcessingContext processingContext, @NotNull final CompletionResultSet completionResultSet) { for (final String keyword : ALL) { final LookupElementBuilder builder = LookupElementBuilder.create(keyword).setBold(); completionResultSet.addElement(builder); } } }); } }