use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class GrPullUpHandler method invokeImpl.
private void invokeImpl(Project project, DataContext dataContext, GrTypeDefinition aClass, PsiElement aMember) {
final Editor editor = dataContext != null ? CommonDataKeys.EDITOR.getData(dataContext) : null;
if (aClass == null) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("is.not.supported.in.the.current.context", REFACTORING_NAME));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
return;
}
ArrayList<PsiClass> bases = RefactoringHierarchyUtil.createBasesList(aClass, false, true);
if (bases.isEmpty()) {
final GrTypeDefinition containingClass = DefaultGroovyMethods.asType(aClass.getContainingClass(), GrTypeDefinition.class);
if (containingClass != null) {
invokeImpl(project, dataContext, containingClass, aClass);
return;
}
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("class.does.not.have.base.classes.interfaces.in.current.project", aClass.getQualifiedName()));
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
return;
}
mySubclass = aClass;
GrMemberInfoStorage memberInfoStorage = new GrMemberInfoStorage((GrTypeDefinition) mySubclass, new MemberInfoBase.Filter<GrMember>() {
@Override
public boolean includeMember(GrMember element) {
return true;
}
});
List<GrMemberInfo> members = memberInfoStorage.getClassMemberInfos(mySubclass);
PsiManager manager = mySubclass.getManager();
for (GrMemberInfo member : members) {
if (manager.areElementsEquivalent(member.getMember(), aMember)) {
member.setChecked(true);
break;
}
}
final GrPullUpDialog dialog = new GrPullUpDialog(project, aClass, bases, memberInfoStorage, this);
dialog.show();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class ReachingDefinitionsCollector method filterNonlocals.
private static VariableInfo[] filterNonlocals(Map<String, VariableInfo> infos, GrStatement place) {
List<VariableInfo> result = new ArrayList<>();
for (Iterator<VariableInfo> iterator = infos.values().iterator(); iterator.hasNext(); ) {
VariableInfo info = iterator.next();
String name = info.getName();
GroovyPsiElement property = ResolveUtil.resolveProperty(place, name);
if (property instanceof GrVariable) {
iterator.remove();
} else if (property instanceof GrReferenceExpression) {
GrMember member = PsiTreeUtil.getParentOfType(property, GrMember.class);
if (member == null) {
continue;
} else if (!member.hasModifierProperty(PsiModifier.STATIC)) {
if (member.getContainingClass() instanceof GroovyScriptClass) {
//binding variable
continue;
}
}
}
if (ResolveUtil.resolveClass(place, name) == null) {
result.add(info);
}
}
return result.toArray(new VariableInfo[result.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class GrDocCommentUtil method findDocOwner.
@Nullable
public static GrDocCommentOwner findDocOwner(GroovyDocPsiElement docElement) {
PsiElement element = docElement;
while (element != null && element.getParent() instanceof GroovyDocPsiElement) element = element.getParent();
if (element == null)
return null;
element = skipWhiteSpacesAndStopOnDoc(element, true);
if (element instanceof GrDocCommentOwner)
return (GrDocCommentOwner) element;
if (element instanceof GrMembersDeclaration) {
GrMember[] members = ((GrMembersDeclaration) element).getMembers();
if (members.length > 0 && members[0] instanceof GrDocCommentOwner) {
return (GrDocCommentOwner) members[0];
}
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class ResolveUtil method processCategoryMembers.
public static boolean processCategoryMembers(@NotNull PsiElement place, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state) {
boolean inCodeBlock = true;
PsiElement run = place;
PsiElement lastParent = null;
while (run != null) {
ProgressManager.checkCanceled();
if (run instanceof GrMember) {
inCodeBlock = false;
}
if (run instanceof GrClosableBlock) {
if (inCodeBlock) {
if (!GdkMethodUtil.categoryIteration((GrClosableBlock) run, processor, state))
return false;
}
PsiClass superClass = getLiteralSuperClass((GrClosableBlock) run);
if (superClass != null && !GdkMethodUtil.processCategoryMethods(run, processor, state, superClass))
return false;
}
if (run instanceof GrStatementOwner) {
if (!GdkMethodUtil.processMixinToMetaclass((GrStatementOwner) run, processor, state, lastParent, place))
return false;
}
lastParent = run;
run = run.getContext();
}
return true;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class ResolveUtil method resolveLabelTargets.
@NotNull
public static Pair<GrStatement, GrLabeledStatement> resolveLabelTargets(@Nullable String labelName, @Nullable PsiElement element, boolean isBreak) {
if (element == null)
return new Pair<>(null, null);
if (labelName == null) {
do {
element = element.getContext();
if (element == null || element instanceof GrClosableBlock || element instanceof GrMember || element instanceof GroovyFile) {
return new Pair<>(null, null);
}
} while (!(element instanceof GrLoopStatement) && !(isBreak && element instanceof GrSwitchStatement));
return new Pair<>(((GrStatement) element), null);
}
GrStatement statement = null;
do {
PsiElement last = element;
element = element.getContext();
if (element == null || element instanceof GrMember || element instanceof GroovyFile)
break;
if (element instanceof GrStatement && !(element instanceof GrClosableBlock)) {
statement = (GrStatement) element;
}
PsiElement sibling = element;
while (sibling != null) {
final GrLabeledStatement labelStatement = findLabelStatementIn(sibling, last, labelName);
if (labelStatement != null) {
return Pair.create(statement, labelStatement);
}
sibling = sibling.getPrevSibling();
}
if (element instanceof GrClosableBlock)
break;
} while (true);
return new Pair<>(null, null);
}
Aggregations