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
.util
.xml
.converters
;
18 import com
.intellij
.util
.xml
.converters
.values
.ClassArrayConverter
;
19 import com
.intellij
.util
.xml
.GenericDomValue
;
20 import com
.intellij
.util
.xml
.ConvertContext
;
21 import com
.intellij
.psi
.PsiReference
;
22 import com
.intellij
.psi
.PsiElement
;
23 import com
.intellij
.psi
.ElementManipulators
;
24 import com
.intellij
.psi
.impl
.source
.resolve
.reference
.impl
.providers
.JavaClassReferenceProvider
;
25 import com
.intellij
.openapi
.project
.Project
;
26 import com
.intellij
.openapi
.util
.UserDataCache
;
27 import org
.jetbrains
.annotations
.NotNull
;
29 import java
.util
.ArrayList
;
30 import java
.util
.List
;
33 * User: Sergey.Vasiliev
35 public class ClassArrayConverterImpl
extends ClassArrayConverter
{
36 private static final UserDataCache
<JavaClassReferenceProvider
, Project
, Object
> REFERENCE_PROVIDER
= new UserDataCache
<JavaClassReferenceProvider
, Project
, Object
>("ClassArrayConverterImpl") {
38 protected JavaClassReferenceProvider
compute(Project project
, Object p
) {
39 JavaClassReferenceProvider provider
= new JavaClassReferenceProvider(project
);
40 provider
.setSoft(true);
41 provider
.setAllowEmpty(true);
47 public PsiReference
[] createReferences(final GenericDomValue genericDomValue
, final PsiElement element
, final ConvertContext context
) {
48 final String s
= genericDomValue
.getStringValue();
50 final int offset
= ElementManipulators
.getOffsetInElement(element
);
51 final ArrayList
<PsiReference
> list
= new ArrayList
<PsiReference
>();
54 while (pos
+ 1 < s
.length()) {
55 if (!Character
.isWhitespace(s
.charAt(pos
+ 1))) {
60 int nextPos
= s
.indexOf(',', pos
+ 1);
62 createReference(element
, s
.substring(pos
+ 1), pos
+ 1 + offset
, list
);
66 createReference(element
, s
.substring(pos
+ 1, nextPos
), pos
+ 1 + offset
, list
);
70 return list
.toArray(new PsiReference
[list
.size()]);
72 return PsiReference
.EMPTY_ARRAY
;
75 private static void createReference(final PsiElement element
, final String s
, final int offset
, List
<PsiReference
> list
) {
76 final PsiReference
[] references
= REFERENCE_PROVIDER
.get(element
.getProject(), null).getReferencesByString(s
, element
, offset
);
77 //noinspection ManualArrayToCollectionCopy
78 for (PsiReference ref
: references
) {