update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / scope / processor / MethodCandidatesProcessor.java
blob4e4c7aa53af5905d279afcab598abf1b3ecbedb6
1 /*
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.scope.processor;
18 import com.intellij.psi.*;
19 import com.intellij.psi.impl.source.resolve.JavaResolveUtil;
20 import com.intellij.psi.infos.CandidateInfo;
21 import com.intellij.psi.infos.MethodCandidateInfo;
22 import com.intellij.psi.scope.PsiConflictResolver;
23 import com.intellij.psi.scope.conflictResolvers.DuplicateConflictResolver;
24 import com.intellij.util.SmartList;
26 /**
27 * Created by IntelliJ IDEA.
28 * User: ik
29 * Date: 31.01.2003
30 * Time: 19:31:12
31 * To change this template use Options | File Templates.
33 public class MethodCandidatesProcessor extends MethodsProcessor{
34 protected boolean myHasAccessibleStaticCorrectCandidate = false;
36 public MethodCandidatesProcessor(PsiElement place, PsiConflictResolver[] resolvers, SmartList<CandidateInfo> container){
37 super(resolvers, container, place);
40 public MethodCandidatesProcessor(PsiElement place){
41 super(new PsiConflictResolver[]{DuplicateConflictResolver.INSTANCE}, new SmartList<CandidateInfo>(), place);
44 public void add(PsiElement element, PsiSubstitutor substitutor) {
45 if (element instanceof PsiMethod){
46 final PsiMethod method = (PsiMethod)element;
47 addMethod(method, substitutor, isInStaticScope() && !method.hasModifierProperty(PsiModifier.STATIC));
51 public void addMethod(final PsiMethod method, final PsiSubstitutor substitutor, final boolean staticProblem) {
52 boolean isAccessible = JavaResolveUtil.isAccessible(method, method.getContainingClass(), method.getModifierList(),
53 myPlace, myAccessClass, myCurrentFileContext);
54 myHasAccessibleStaticCorrectCandidate |= isAccessible && !staticProblem;
56 if (isAccepted(method)) {
57 add(createCandidateInfo(method, substitutor, staticProblem, isAccessible));
61 protected MethodCandidateInfo createCandidateInfo(final PsiMethod method, final PsiSubstitutor substitutor,
62 final boolean staticProblem,
63 final boolean accessible) {
64 return new MethodCandidateInfo(method, substitutor, !accessible, staticProblem, getArgumentList(), myCurrentFileContext,
65 getArgumentList().getExpressionTypes(), getTypeArguments());
68 protected boolean isAccepted(final PsiMethod candidate) {
69 if (!isConstructor()) {
70 return !candidate.isConstructor() && getName(ResolveState.initial()).equals(candidate.getName());
72 else {
73 if (!candidate.isConstructor()) return false;
74 if (myAccessClass == null) return true;
75 if (myAccessClass instanceof PsiAnonymousClass) {
76 return candidate.getContainingClass().equals(myAccessClass.getSuperClass());
78 return myAccessClass.equals(candidate.getContainingClass());
82 public CandidateInfo[] getCandidates() {
83 final JavaResolveResult[] resolveResult = getResult();
84 CandidateInfo[] infos = new CandidateInfo[resolveResult.length];
85 System.arraycopy(resolveResult, 0, infos, 0, resolveResult.length);
86 return infos;