use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class DuplicateConflictResolver method resolveConflict.
@Override
public CandidateInfo resolveConflict(@NotNull List<CandidateInfo> conflicts) {
if (conflicts.size() == 1)
return conflicts.get(0);
final Map<Object, CandidateInfo> uniqueItems = new HashMap<>();
for (CandidateInfo info : conflicts) {
final PsiElement element = info.getElement();
Object key;
if (info instanceof MethodCandidateInfo) {
key = ((PsiMethod) element).getSignature(((MethodCandidateInfo) info).getSubstitutor(false));
} else {
key = PsiUtilCore.getName(element);
}
if (!uniqueItems.containsKey(key)) {
uniqueItems.put(key, info);
}
}
if (uniqueItems.size() == 1)
return uniqueItems.values().iterator().next();
return null;
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class GroovyOverrideImplementExploreUtil method collectMethodsToImplement.
public static void collectMethodsToImplement(PsiClass aClass, Map<MethodSignature, PsiMethod> abstracts, Map<MethodSignature, PsiMethod> finals, Map<MethodSignature, PsiMethod> concretes, Map<MethodSignature, CandidateInfo> result) {
for (Map.Entry<MethodSignature, PsiMethod> entry : abstracts.entrySet()) {
MethodSignature signature = entry.getKey();
PsiMethod abstractOne = entry.getValue();
PsiMethod concrete = concretes.get(signature);
if (concrete == null || PsiUtil.getAccessLevel(concrete.getModifierList()) < PsiUtil.getAccessLevel(abstractOne.getModifierList()) || !abstractOne.getContainingClass().isInterface() && abstractOne.getContainingClass().isInheritor(concrete.getContainingClass(), true) || isDefaultMethod(abstractOne)) {
if (finals.get(signature) == null) {
PsiSubstitutor subst = OverrideImplementExploreUtil.correctSubstitutor(abstractOne, signature.getSubstitutor());
CandidateInfo info = new CandidateInfo(abstractOne, subst);
result.put(signature, info);
}
}
}
for (final PsiMethod method : new GroovyMethodImplementor().getMethodsToImplement(aClass)) {
MethodSignature signature = MethodSignatureUtil.createMethodSignature(method.getName(), method.getParameterList(), method.getTypeParameterList(), PsiSubstitutor.EMPTY, method.isConstructor());
CandidateInfo info = new CandidateInfo(method, PsiSubstitutor.EMPTY);
result.put(signature, info);
}
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class GroovyOverrideImplementUtil method chooseAndOverrideOrImplementMethods.
public static void chooseAndOverrideOrImplementMethods(@NotNull Project project, @NotNull final Editor editor, @NotNull final GrTypeDefinition aClass, boolean toImplement) {
LOG.assertTrue(aClass.isValid());
ApplicationManager.getApplication().assertReadAccessAllowed();
Collection<CandidateInfo> candidates = GroovyOverrideImplementExploreUtil.getMethodsToOverrideImplement(aClass, toImplement);
Collection<CandidateInfo> secondary = toImplement || aClass.isInterface() ? ContainerUtil.<CandidateInfo>newArrayList() : GroovyOverrideImplementExploreUtil.getMethodsToOverrideImplement(aClass, true);
if (toImplement) {
for (Iterator<CandidateInfo> iterator = candidates.iterator(); iterator.hasNext(); ) {
CandidateInfo candidate = iterator.next();
PsiElement element = candidate.getElement();
if (element instanceof GrMethod) {
GrMethod method = (GrMethod) element;
if (GrTraitUtil.isTrait(method.getContainingClass()) && !GrTraitUtil.isMethodAbstract(method)) {
iterator.remove();
secondary.add(candidate);
}
}
}
}
final MemberChooser<PsiMethodMember> chooser = OverrideImplementUtil.showOverrideImplementChooser(editor, aClass, toImplement, candidates, secondary);
if (chooser == null)
return;
final List<PsiMethodMember> selectedElements = chooser.getSelectedElements();
if (selectedElements == null || selectedElements.isEmpty())
return;
LOG.assertTrue(aClass.isValid());
new WriteCommandAction(project, aClass.getContainingFile()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
OverrideImplementUtil.overrideOrImplementMethodsInRightPlace(editor, aClass, selectedElements, chooser.isCopyJavadoc(), chooser.isInsertOverrideAnnotation());
}
}.execute();
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class GrClassImplUtil method processDeclarations.
public static boolean processDeclarations(@NotNull GrTypeDefinition grType, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
if (place instanceof GrCodeReferenceElement && lastParent instanceof GrModifierList) {
final PsiElement possibleAnnotation = PsiTreeUtil.skipParentsOfType(place, GrCodeReferenceElement.class);
if (possibleAnnotation instanceof GrAnnotation && possibleAnnotation.getParent() == lastParent) {
//don't process class members while resolving annotation which annotates current class
return true;
}
}
for (final PsiTypeParameter typeParameter : grType.getTypeParameters()) {
if (!ResolveUtil.processElement(processor, typeParameter, state))
return false;
}
NameHint nameHint = processor.getHint(NameHint.KEY);
String name = nameHint == null ? null : nameHint.getName(state);
ElementClassHint classHint = processor.getHint(ElementClassHint.KEY);
final PsiSubstitutor substitutor = state.get(PsiSubstitutor.KEY);
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject());
boolean processInstanceMethods = (ResolveUtil.shouldProcessMethods(classHint) || ResolveUtil.shouldProcessProperties(classHint)) && shouldProcessInstanceMembers(grType, lastParent);
LanguageLevel level = PsiUtil.getLanguageLevel(place);
if (ResolveUtil.shouldProcessProperties(classHint)) {
Map<String, CandidateInfo> fieldsMap = CollectClassMembersUtil.getAllFields(grType);
if (name != null) {
CandidateInfo fieldInfo = fieldsMap.get(name);
if (fieldInfo != null) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, fieldInfo)) {
return false;
}
} else if (grType.isTrait() && lastParent != null) {
PsiField field = findFieldByName(grType, name, false, true);
if (field != null && field.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
return false;
}
}
}
} else {
for (CandidateInfo info : fieldsMap.values()) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, info)) {
return false;
}
}
if (grType.isTrait() && lastParent != null) {
for (PsiField field : CollectClassMembersUtil.getFields(grType, true)) {
if (field.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!processField(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, new CandidateInfo(field, PsiSubstitutor.EMPTY))) {
return false;
}
}
}
}
}
}
if (ResolveUtil.shouldProcessMethods(classHint)) {
Map<String, List<CandidateInfo>> methodsMap = CollectClassMembersUtil.getAllMethods(grType, true);
boolean isPlaceGroovy = place.getLanguage() == GroovyLanguage.INSTANCE;
if (name == null) {
for (List<CandidateInfo> list : methodsMap.values()) {
for (CandidateInfo info : list) {
if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
return false;
}
}
}
} else {
List<CandidateInfo> byName = methodsMap.get(name);
if (byName != null) {
for (CandidateInfo info : byName) {
if (!processMethod(grType, processor, state, place, processInstanceMethods, substitutor, factory, level, isPlaceGroovy, info)) {
return false;
}
}
}
}
}
final GrTypeDefinitionBody body = grType.getBody();
if (body != null) {
if (ResolveUtil.shouldProcessClasses(classHint)) {
for (PsiClass innerClass : getInnerClassesForResolve(grType, lastParent, place)) {
if (name != null && !name.equals(innerClass.getName()))
continue;
if (!processor.execute(innerClass, state))
return false;
}
}
}
return true;
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class GrClassImplUtil method findFieldByName.
@Nullable
public static PsiField findFieldByName(GrTypeDefinition grType, String name, boolean checkBases, boolean includeSynthetic) {
if (!checkBases) {
for (PsiField field : CollectClassMembersUtil.getFields(grType, includeSynthetic)) {
if (name.equals(field.getName()))
return field;
}
return null;
}
Map<String, CandidateInfo> fieldsMap = CollectClassMembersUtil.getAllFields(grType, includeSynthetic);
final CandidateInfo info = fieldsMap.get(name);
return info == null ? null : (PsiField) info.getElement();
}
Aggregations