use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class ResolverProcessor method isAccessible.
protected boolean isAccessible(@NotNull PsiNamedElement namedElement) {
if (namedElement instanceof GrField) {
final GrField field = (GrField) namedElement;
if (PsiUtil.isAccessible(myPlace, field)) {
return true;
}
for (GrAccessorMethod method : field.getGetters()) {
if (PsiUtil.isAccessible(myPlace, method)) {
return true;
}
}
final GrAccessorMethod setter = field.getSetter();
if (setter != null && PsiUtil.isAccessible(myPlace, setter)) {
return true;
}
return false;
}
return !(namedElement instanceof PsiMember) || PsiUtil.isAccessible(myPlace, ((PsiMember) namedElement));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GrMethodConflictUtil method checkForClosurePropertySignatureOverload.
private static void checkForClosurePropertySignatureOverload(PsiClass clazz, GrMethod prototype, final GrMethod refactoredMethod, final MultiMap<PsiElement, String> conflicts, final List<MethodSignature> prototypeSignatures) {
final boolean isStatic = prototype.hasModifierProperty(PsiModifier.STATIC);
final String name = prototype.getName();
if (!GroovyPropertyUtils.isProperty(clazz, name, isStatic))
return;
final PsiMethod getter = GroovyPropertyUtils.findPropertyGetter(clazz, name, isStatic, true);
final PsiType returnType;
if (getter instanceof GrMethod) {
returnType = ((GrMethod) getter).getInferredReturnType();
} else if (getter instanceof GrAccessorMethod) {
returnType = ((GrAccessorMethod) getter).getInferredReturnType();
} else {
return;
}
if (!(returnType instanceof GrClosureType))
return;
final GrSignature signature = ((GrClosureType) returnType).getSignature();
signature.accept(new GrRecursiveSignatureVisitor() {
@Override
public void visitClosureSignature(GrClosureSignature signature) {
NextSignature: for (MethodSignature prototypeSignature : prototypeSignatures) {
final GrClosureParameter[] params = signature.getParameters();
final PsiType[] types = prototypeSignature.getParameterTypes();
if (types.length != params.length)
continue;
for (int i = 0; i < types.length; i++) {
if (!TypesUtil.isAssignableByMethodCallConversion(types[i], params[i].getType(), refactoredMethod.getParameterList())) {
continue NextSignature;
}
}
conflicts.putValue(getter, GroovyRefactoringBundle.message("refactored.method.will.cover.closure.property", name, RefactoringUIUtil.getDescription(getter.getContainingClass(), false)));
}
}
});
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class GrAnnotatorImpl method annotate.
@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
if (FileIndexFacade.getInstance(element.getProject()).isInLibrarySource(element.getContainingFile().getVirtualFile()))
return;
if (element instanceof GroovyPsiElement) {
final GroovyAnnotator annotator = new GroovyAnnotator(holder);
((GroovyPsiElement) element).accept(annotator);
if (PsiUtil.isCompileStatic(element)) {
final GroovyStaticTypeCheckVisitor typeCheckVisitor = myTypeCheckVisitorThreadLocal.get();
assert typeCheckVisitor != null;
typeCheckVisitor.accept((GroovyPsiElement) element, holder);
}
} else if (element instanceof PsiComment) {
String text = element.getText();
if (text.startsWith("/*") && !(text.endsWith("*/"))) {
TextRange range = element.getTextRange();
holder.createErrorAnnotation(TextRange.create(range.getEndOffset() - 1, range.getEndOffset()), GroovyBundle.message("doc.end.expected"));
}
} else {
final PsiElement parent = element.getParent();
if (parent instanceof GrMethod) {
if (element.equals(((GrMethod) parent).getNameIdentifierGroovy()) && ((GrMethod) parent).getReturnTypeElementGroovy() == null) {
GroovyAnnotator.checkMethodReturnType((GrMethod) parent, element, holder);
}
} else if (parent instanceof GrField) {
final GrField field = (GrField) parent;
if (element.equals(field.getNameIdentifierGroovy())) {
final GrAccessorMethod[] getters = field.getGetters();
for (GrAccessorMethod getter : getters) {
GroovyAnnotator.checkMethodReturnType(getter, field.getNameIdentifierGroovy(), holder);
}
final GrAccessorMethod setter = field.getSetter();
if (setter != null) {
GroovyAnnotator.checkMethodReturnType(setter, field.getNameIdentifierGroovy(), holder);
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class RenameGrFieldProcessor method findExistingNameConflicts.
@Override
public void findExistingNameConflicts(PsiElement element, String newName, MultiMap<PsiElement, String> conflicts) {
super.findExistingNameConflicts(element, newName, conflicts);
GrField field = (GrField) element;
final PsiClass containingClass = field.getContainingClass();
if (containingClass == null)
return;
final PsiMethod getter = GroovyPropertyUtils.findGetterForField(field);
if (getter instanceof GrAccessorMethod) {
final PsiMethod newGetter = PropertyUtil.findPropertyGetter(containingClass, newName, field.hasModifierProperty(PsiModifier.STATIC), true);
if (newGetter != null && !(newGetter instanceof GrAccessorMethod)) {
conflicts.putValue(newGetter, GroovyRefactoringBundle.message("implicit.getter.will.by.overriden.by.method", field.getName(), newGetter.getName()));
}
}
final PsiMethod setter = GroovyPropertyUtils.findSetterForField(field);
if (setter instanceof GrAccessorMethod) {
final PsiMethod newSetter = PropertyUtil.findPropertySetter(containingClass, newName, field.hasModifierProperty(PsiModifier.STATIC), true);
if (newSetter != null && !(newSetter instanceof GrAccessorMethod)) {
conflicts.putValue(newSetter, GroovyRefactoringBundle.message("implicit.setter.will.by.overriden.by.method", field.getName(), newSetter.getName()));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod in project intellij-community by JetBrains.
the class JavaStylePropertiesUtil method areEquivalentAccessors.
private static boolean areEquivalentAccessors(PsiMethod method, PsiElement resolved, PsiManager manager) {
if (!(resolved instanceof GrAccessorMethod) || !(method instanceof GrAccessorMethod)) {
return false;
}
if (((GrAccessorMethod) resolved).isSetter() != ((GrAccessorMethod) method).isSetter())
return false;
GrField p1 = ((GrAccessorMethod) resolved).getProperty();
GrField p2 = ((GrAccessorMethod) method).getProperty();
return manager.areElementsEquivalent(p1, p2);
}
Aggregations