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();
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class GrClassImplUtil method getAllMethodsAndTheirSubstitutors.
@NotNull
public static List<Pair<PsiMethod, PsiSubstitutor>> getAllMethodsAndTheirSubstitutors(GrTypeDefinition grType) {
final Map<String, List<CandidateInfo>> allMethodsMap = CollectClassMembersUtil.getAllMethods(grType, true);
List<Pair<PsiMethod, PsiSubstitutor>> result = new ArrayList<>();
for (List<CandidateInfo> infos : allMethodsMap.values()) {
for (CandidateInfo info : infos) {
result.add(Pair.create((PsiMethod) info.getElement(), info.getSubstitutor()));
}
}
return result;
}
use of com.intellij.psi.infos.CandidateInfo in project intellij-community by JetBrains.
the class GrClassImplUtil method findMethodsAndTheirSubstitutorsByName.
@NotNull
public static List<Pair<PsiMethod, PsiSubstitutor>> findMethodsAndTheirSubstitutorsByName(GrTypeDefinition grType, String name, boolean checkBases) {
final ArrayList<Pair<PsiMethod, PsiSubstitutor>> result = new ArrayList<>();
if (!checkBases) {
final PsiMethod[] methods = grType.findMethodsByName(name, false);
for (PsiMethod method : methods) {
result.add(Pair.create(method, PsiSubstitutor.EMPTY));
}
} else {
final Map<String, List<CandidateInfo>> map = CollectClassMembersUtil.getAllMethods(grType, true);
final List<CandidateInfo> candidateInfos = map.get(name);
if (candidateInfos != null) {
for (CandidateInfo info : candidateInfos) {
final PsiElement element = info.getElement();
result.add(Pair.create((PsiMethod) element, info.getSubstitutor()));
}
}
}
return result;
}
Aggregations