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
.psi
.filters
.getters
;
18 import com
.intellij
.codeInsight
.completion
.CompletionContext
;
19 import com
.intellij
.psi
.PsiElement
;
20 import com
.intellij
.psi
.filters
.ContextGetter
;
21 import com
.intellij
.psi
.util
.PsiTreeUtil
;
22 import com
.intellij
.psi
.xml
.XmlAttribute
;
23 import com
.intellij
.psi
.xml
.XmlAttributeValue
;
24 import com
.intellij
.psi
.xml
.XmlElement
;
25 import com
.intellij
.util
.ArrayUtil
;
26 import com
.intellij
.xml
.XmlAttributeDescriptor
;
27 import com
.intellij
.xml
.impl
.BasicXmlAttributeDescriptor
;
28 import org
.jetbrains
.annotations
.Nullable
;
31 * Created by IntelliJ IDEA.
35 * To change this template use Options | File Templates.
37 public class XmlAttributeValueGetter
implements ContextGetter
{
38 public XmlAttributeValueGetter() {}
40 public Object
[] get(PsiElement context
, CompletionContext completionContext
) {
41 return getApplicableAttributeVariants(context
, completionContext
);
44 private Object
[] getApplicableAttributeVariants(PsiElement _context
, CompletionContext completionContext
) {
45 PsiElement context
= _context
;
47 context
= PsiTreeUtil
.getParentOfType(context
, XmlAttribute
.class);
48 if (context
== null) {
49 context
= PsiTreeUtil
.getParentOfType(_context
, XmlAttributeValue
.class);
53 if(context
instanceof XmlAttribute
) {
54 final XmlAttributeDescriptor descriptor
= ((XmlAttribute
)context
).getDescriptor();
56 if(descriptor
!= null) {
57 if (descriptor
.isFixed()) {
58 final String defaultValue
= descriptor
.getDefaultValue();
59 return defaultValue
== null ? ArrayUtil
.EMPTY_OBJECT_ARRAY
: new Object
[] { defaultValue
};
62 String
[] values
= descriptor
instanceof BasicXmlAttributeDescriptor ?
63 ((BasicXmlAttributeDescriptor
)descriptor
).getEnumeratedValues((XmlElement
)context
):descriptor
.getEnumeratedValues();
65 final String
[] strings
= addSpecificCompletions(context
);
67 if(values
== null || values
.length
==0) {
69 } else if (strings
!= null) {
70 values
= ArrayUtil
.mergeArrays(values
, strings
, String
.class);
73 return values
== null ? ArrayUtil
.EMPTY_OBJECT_ARRAY
: values
;
77 return ArrayUtil
.EMPTY_OBJECT_ARRAY
;
81 protected String
[] addSpecificCompletions(final PsiElement context
) {