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
.uiDesigner
;
18 import com
.intellij
.openapi
.module
.Module
;
19 import com
.intellij
.psi
.*;
20 import com
.intellij
.psi
.search
.GlobalSearchScope
;
21 import com
.intellij
.psi
.util
.ClassUtil
;
22 import com
.intellij
.psi
.util
.InheritanceUtil
;
23 import com
.intellij
.psi
.util
.PropertyUtil
;
24 import com
.intellij
.uiDesigner
.lw
.*;
25 import org
.jetbrains
.annotations
.NotNull
;
26 import org
.jetbrains
.annotations
.Nullable
;
30 import java
.util
.HashMap
;
33 * @author Anton Katilin
34 * @author Vladimir Kondratyev
36 public final class PsiPropertiesProvider
implements PropertiesProvider
{
37 private final Module myModule
;
38 private final HashMap
<String
, HashMap
> myCache
;
40 public PsiPropertiesProvider(@NotNull final Module module
) {
42 myCache
= new HashMap
<String
, HashMap
>();
46 public HashMap
getLwProperties(final String className
) {
47 if (myCache
.containsKey(className
)) {
48 return myCache
.get(className
);
51 final PsiManager psiManager
= PsiManager
.getInstance(myModule
.getProject());
52 final GlobalSearchScope scope
= GlobalSearchScope
.moduleWithDependenciesAndLibrariesScope(myModule
);
53 final PsiClass aClass
= JavaPsiFacade
.getInstance(psiManager
.getProject()).findClass(className
, scope
);
58 final HashMap result
= new HashMap();
60 final PsiMethod
[] methods
= aClass
.getAllMethods();
61 for (final PsiMethod method
: methods
) {
62 // it's a setter candidate.. try to find getter
64 if (!PropertyUtil
.isSimplePropertySetter(method
)) {
67 final String name
= PropertyUtil
.getPropertyName(method
);
69 throw new IllegalStateException();
71 final PsiMethod getter
= PropertyUtil
.findPropertyGetter(aClass
, name
, false, true);
76 final PsiType type
= getter
.getReturnType();
77 final String propertyClassName
= type
.getCanonicalText();
79 LwIntrospectedProperty property
= CompiledClassPropertiesProvider
.propertyFromClassName(propertyClassName
, name
);
80 if (property
== null) {
81 PsiClass propClass
= JavaPsiFacade
.getInstance(psiManager
.getProject()).findClass(propertyClassName
, scope
);
82 if (propClass
== null) continue;
83 if (propClass
.isEnum()) {
84 final String enumClassName
= ClassUtil
.getJVMClassName(propClass
);
85 final ClassLoader loader
= LoaderFactory
.getInstance(myModule
.getProject()).getLoader(myModule
);
87 property
= new LwIntroEnumProperty(name
, loader
.loadClass(enumClassName
));
89 catch (ClassNotFoundException e
) {
94 PsiClass componentClass
= JavaPsiFacade
.getInstance(psiManager
.getProject()).findClass(Component
.class.getName(), scope
);
95 PsiClass listModelClass
= JavaPsiFacade
.getInstance(psiManager
.getProject()).findClass(ListModel
.class.getName(), scope
);
96 if (componentClass
!= null && InheritanceUtil
.isInheritorOrSelf(propClass
, componentClass
, true)) {
97 property
= new LwIntroComponentProperty(name
, propertyClassName
);
99 else if (componentClass
!= null && listModelClass
!= null && InheritanceUtil
.isInheritorOrSelf(propClass
, listModelClass
, true)) {
100 property
= new LwIntroListModelProperty(name
, propertyClassName
);
103 // type is not supported
109 result
.put(name
, property
);
112 myCache
.put(className
, result
);