private static void checkScriptField(AnnotationHolder holder, GrAnnotation annotation) { final PsiAnnotationOwner owner = annotation.getOwner(); final GrMember container = PsiTreeUtil.getParentOfType(((PsiElement) owner), GrMember.class); if (container != null) { if (container.getContainingClass() instanceof GroovyScriptClass) { holder.createErrorAnnotation( annotation, GroovyBundle.message("annotation.field.can.only.be.used.within.a.script.body")); } else { holder.createErrorAnnotation( annotation, GroovyBundle.message("annotation.field.can.only.be.used.within.a.script")); } } }
@Override protected void visitClassMemberReferenceElement(GrMember classMember, GrReferenceElement ref) { if (classMember != null && !willBeMoved(classMember, myMovedMembers)) { final PsiClass containingClass = classMember.getContainingClass(); if (containingClass != null && !PsiUtil.isAccessibleFromPackage(classMember, myTargetPackage) && (classMember.hasModifierProperty(PsiModifier.PACKAGE_LOCAL) || classMember.hasModifierProperty(PsiModifier.PROTECTED) && !mySubClass.isInheritor(containingClass, true))) { myConflicts.putValue( myMember, RefactoringUIUtil.getDescription(classMember, true) + " won't be accessible"); } } }
@Override protected void visitClassMemberReferenceElement( GrMember classMember, GrReferenceElement classMemberReference) { if (classMember.hasModifierProperty( PsiModifier.STATIC) /*&& classMemberReference.isQualified()*/) { if (!myMovedMembers.contains(classMember) && RefactoringHierarchyUtil.isMemberBetween( myTargetSuperClass, mySourceClass, classMember)) { myReferences.add(classMemberReference); myReferees.add(classMember); myRefereeClasses.add(classMember.getContainingClass()); } else if (myMovedMembers.contains(classMember) || myMembersAfterMove.contains(classMember)) { myReferences.add(classMemberReference); myReferees.add(classMember); myRefereeClasses.add(myTargetSuperClass); } } }
private static void checkSuperclassMembers( PsiClass superClass, MemberInfoBase<? extends GrMember>[] infos, MultiMap<PsiElement, String> conflictsList) { for (MemberInfoBase<? extends GrMember> info : infos) { GrMember member = info.getMember(); boolean isConflict = false; if (member instanceof PsiField) { String name = member.getName(); isConflict = superClass.findFieldByName(name, false) != null; } else if (member instanceof PsiMethod) { PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor( superClass, member.getContainingClass(), PsiSubstitutor.EMPTY); MethodSignature signature = ((PsiMethod) member).getSignature(superSubstitutor); final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(superClass, signature, false); isConflict = superClassMethod != null; } if (isConflict) { String message = RefactoringBundle.message( "0.already.contains.a.1", RefactoringUIUtil.getDescription(superClass, false), RefactoringUIUtil.getDescription(member, false)); message = CommonRefactoringUtil.capitalize(message); conflictsList.putValue(superClass, message); } if (member instanceof PsiMethod) { final PsiMethod method = (PsiMethod) member; final PsiModifierList modifierList = method.getModifierList(); if (!modifierList.hasModifierProperty(PsiModifier.PRIVATE)) { for (PsiClass subClass : ClassInheritorsSearch.search(superClass)) { if (method.getContainingClass() != subClass) { MethodSignature signature = ((PsiMethod) member) .getSignature( TypeConversionUtil.getSuperClassSubstitutor( superClass, subClass, PsiSubstitutor.EMPTY)); final PsiMethod wouldBeOverriden = MethodSignatureUtil.findMethodBySignature(subClass, signature, false); if (wouldBeOverriden != null && VisibilityUtil.compare( VisibilityUtil.getVisibilityModifier(wouldBeOverriden.getModifierList()), VisibilityUtil.getVisibilityModifier(modifierList)) > 0) { conflictsList.putValue( wouldBeOverriden, CommonRefactoringUtil.capitalize( RefactoringUIUtil.getDescription(method, true) + " in super class would clash with local method from " + RefactoringUIUtil.getDescription(subClass, true))); } } } } } } }