Search in sources :

Example 16 with GrAccessorMethod

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));
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) PsiMember(com.intellij.psi.PsiMember)

Example 17 with GrAccessorMethod

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)));
            }
        }
    });
}
Also used : MethodSignature(com.intellij.psi.util.MethodSignature) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) GrClosureParameter(org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) GrRecursiveSignatureVisitor(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrRecursiveSignatureVisitor) GrClosureSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature) GrSignature(org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrSignature) GrClosureType(org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType)

Example 18 with GrAccessorMethod

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);
                }
            }
        }
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) PsiComment(com.intellij.psi.PsiComment) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GroovyStaticTypeCheckVisitor(org.jetbrains.plugins.groovy.codeInspection.type.GroovyStaticTypeCheckVisitor) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 19 with GrAccessorMethod

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()));
        }
    }
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod)

Example 20 with GrAccessorMethod

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);
}
Also used : GrAccessorMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)

Aggregations

GrAccessorMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAccessorMethod)25 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)13 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)6 PsiElement (com.intellij.psi.PsiElement)5 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 Nullable (org.jetbrains.annotations.Nullable)5 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)5 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)4 MultiMap (com.intellij.util.containers.MultiMap)3 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)3 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)3 Editor (com.intellij.openapi.editor.Editor)2 Project (com.intellij.openapi.project.Project)2 PsiMethod (com.intellij.psi.PsiMethod)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 UsageInfo (com.intellij.usageView.UsageInfo)2 GroovyFileBase (org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase)2 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)2