/*
- * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
- * Use is subject to license terms.
+ * Copyright 2000-2009 JetBrains s.r.o.
+ *
+ * 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.util.xml.impl;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider;
-import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.InheritanceUtil;
+import com.intellij.psi.util.PsiUtil;
+import com.intellij.util.ProcessingContext;
import com.intellij.util.ReflectionCache;
import com.intellij.util.SmartList;
-import com.intellij.util.ProcessingContext;
import com.intellij.util.xml.*;
import com.intellij.util.xml.highlighting.DomCustomAnnotationChecker;
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder;
final boolean allowEnum,
final DomElementAnnotationHolder holder) {
final Project project = element.getManager().getProject();
- PsiClass extendClass = JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project));
+ PsiClass extendClass = JavaPsiFacade.getInstance(project).findClass(name, value.getResolveScope());
final SmartList<DomElementProblemDescriptor> list = new SmartList<DomElementProblemDescriptor>();
if (extendClass != null) {
if (!name.equals(value.getQualifiedName()) && !value.isInheritor(extendClass, true)) {
else if (!allowNonPublic && !value.hasModifierProperty(PsiModifier.PUBLIC)) {
list.add(holder.createProblem(element, DomBundle.message("class.is.not.public", value.getQualifiedName())));
}
- else if (!hasDefaultConstructor(value)) {
+ else if (!PsiUtil.hasDefaultConstructor(value, true)) {
if (canBeDecorator) {
boolean hasConstructor = false;
for (PsiMethod method : value.getConstructors()) {
final PsiParameterList psiParameterList = method.getParameterList();
if (psiParameterList.getParametersCount() != 1) continue;
- final PsiType psiType = psiParameterList.getParameters()[0].getTypeElement().getType();
- if (psiType instanceof PsiClassType) {
- final PsiClass psiClass = ((PsiClassType)psiType).resolve();
- if (psiClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, extendClass, true)) {
- hasConstructor = true;
- break;
+ PsiTypeElement typeElement = psiParameterList.getParameters()[0].getTypeElement();
+ if (typeElement != null) {
+ final PsiType psiType = typeElement.getType();
+ if (psiType instanceof PsiClassType) {
+ final PsiClass psiClass = ((PsiClassType)psiType).resolve();
+ if (psiClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, extendClass, true)) {
+ hasConstructor = true;
+ break;
+ }
}
}
}
return list;
}
- public static boolean hasDefaultConstructor(PsiClass clazz) {
- final PsiMethod[] constructors = clazz.getConstructors();
- if (constructors.length > 0) {
- for (PsiMethod cls: constructors) {
- if ((cls.hasModifierProperty(PsiModifier.PUBLIC) || cls.hasModifierProperty(PsiModifier.PROTECTED)) && cls.getParameterList().getParametersCount() == 0) {
- return true;
- }
- }
- } else {
- final PsiClass superClass = clazz.getSuperClass();
- return superClass == null || hasDefaultConstructor(superClass);
- }
- return false;
- }
-
public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
final Object valueObject = element.getValue();
if (!(valueObject instanceof PsiClass)) return Collections.emptyList();