use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class PsiImplUtil method getQualifierType.
@Nullable
public static PsiType getQualifierType(@NotNull GrReferenceExpression ref) {
final GrExpression rtQualifier = getRuntimeQualifier(ref);
if (rtQualifier != null) {
return rtQualifier.getType();
}
PsiClass containingClass = null;
final GrMember member = PsiTreeUtil.getParentOfType(ref, GrMember.class);
if (member == null) {
final PsiFile file = ref.getContainingFile();
if (file instanceof GroovyFileBase && ((GroovyFileBase) file).isScript()) {
containingClass = ((GroovyFileBase) file).getScriptClass();
} else {
return null;
}
} else if (member instanceof GrMethod) {
if (!member.hasModifierProperty(PsiModifier.STATIC)) {
containingClass = member.getContainingClass();
}
}
if (containingClass != null) {
final PsiClassType categoryType = GdkMethodUtil.getCategoryType(containingClass);
if (categoryType != null) {
return categoryType;
}
return JavaPsiFacade.getElementFactory(ref.getProject()).createType(containingClass);
}
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 isScriptField.
public static boolean isScriptField(GrVariable var) {
GrModifierList list = var.getModifierList();
if (list == null)
return false;
PsiFile containingFile = var.getContainingFile();
if (!(containingFile instanceof GroovyFile) || !((GroovyFile) containingFile).isScript())
return false;
GrMember member = PsiTreeUtil.getParentOfType(var, GrTypeDefinition.class, GrMethod.class);
if (member != null)
return false;
for (GrAnnotation annotation : list.getAnnotations()) {
String qualifiedName = annotation.getQualifiedName();
if (qualifiedName == null)
continue;
if (qualifiedName.equals(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD))
return true;
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class GrRefactoringConflictsUtil method analyzeAccessibilityConflicts.
public static void analyzeAccessibilityConflicts(@NotNull Set<GrMember> membersToMove, @Nullable PsiClass targetClass, @NotNull MultiMap<PsiElement, String> conflicts, @Nullable String newVisibility, @NotNull PsiElement context, @Nullable Set<PsiMethod> abstractMethods) {
if (VisibilityUtil.ESCALATE_VISIBILITY.equals(newVisibility)) {
//Still need to check for access object
newVisibility = PsiModifier.PUBLIC;
}
for (GrMember member : membersToMove) {
checkUsedElements(member, member, membersToMove, abstractMethods, targetClass, context, conflicts);
RefactoringConflictsUtil.checkAccessibilityConflicts(member, newVisibility, targetClass, membersToMove, conflicts);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class GrPullUpConflictsUtil method checkSuperclassMembers.
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)));
}
}
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember in project intellij-community by JetBrains.
the class GrPullUpConflictsUtil method checkInterfaceTarget.
private static void checkInterfaceTarget(MemberInfoBase<? extends GrMember>[] infos, MultiMap<PsiElement, String> conflictsList) {
for (MemberInfoBase<? extends GrMember> info : infos) {
GrMember member = info.getMember();
if (member instanceof PsiField || member instanceof PsiClass) {
if (!member.hasModifierProperty(PsiModifier.STATIC) && !(member instanceof PsiClass && ((PsiClass) member).isInterface())) {
String message = RefactoringBundle.message("0.is.not.static.it.cannot.be.moved.to.the.interface", RefactoringUIUtil.getDescription(member, false));
message = CommonRefactoringUtil.capitalize(message);
conflictsList.putValue(member, message);
}
}
if (member instanceof PsiField && ((PsiField) member).getInitializer() == null) {
String message = RefactoringBundle.message("0.is.not.initialized.in.declaration.such.fields.are.not.allowed.in.interfaces", RefactoringUIUtil.getDescription(member, false));
conflictsList.putValue(member, CommonRefactoringUtil.capitalize(message));
}
}
}
Aggregations