Search in sources :

Example 51 with GrTypeDefinition

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.

the class ClashingGettersInspection method buildVisitor.

@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
    return new BaseInspectionVisitor() {

        @Override
        public void visitTypeDefinition(@NotNull GrTypeDefinition typeDefinition) {
            super.visitTypeDefinition(typeDefinition);
            Map<String, PsiMethod> getters = new HashMap<>();
            for (PsiMethod method : typeDefinition.getMethods()) {
                final String methodName = method.getName();
                if (!GroovyPropertyUtils.isSimplePropertyGetter(method))
                    continue;
                final String propertyName = GroovyPropertyUtils.getPropertyNameByGetterName(methodName, true);
                final PsiMethod otherGetter = getters.get(propertyName);
                if (otherGetter != null && !methodName.equals(otherGetter.getName())) {
                    final Pair<PsiElement, String> description = getGetterDescription(method);
                    final Pair<PsiElement, String> otherDescription = getGetterDescription(otherGetter);
                    if (description.first != null) {
                        registerError(description.first, description.second, otherDescription.second);
                    }
                    if (otherDescription.first != null) {
                        registerError(otherDescription.first, otherDescription.second, description.second);
                    }
                } else {
                    getters.put(propertyName, method);
                }
            }
        }
    };
}
Also used : BaseInspectionVisitor(org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) HashMap(java.util.HashMap) PsiMethod(com.intellij.psi.PsiMethod) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with GrTypeDefinition

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.

the class BindableTransformationSupport method applyTransformation.

@Override
public void applyTransformation(@NotNull TransformationContext context) {
    GrTypeDefinition clazz = context.getCodeClass();
    if (!isApplicable(clazz))
        return;
    final PsiManager manager = clazz.getManager();
    final GlobalSearchScope scope = clazz.getResolveScope();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(clazz.getProject());
    final PsiType pclType = facade.getElementFactory().createTypeByFQClassName(PCL_FQN, scope);
    final PsiArrayType pclArrayType = new PsiArrayType(pclType);
    final PsiType stringType = PsiType.getJavaLangString(manager, scope);
    final PsiType objectType = PsiType.getJavaLangObject(manager, scope);
    final List<LightMethodBuilder> methods = ContainerUtil.newArrayList();
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "addPropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("listener", pclType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "addPropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("listener", pclType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "removePropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("listener", pclType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "removePropertyChangeListener").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("listener", pclType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "firePropertyChange").setMethodReturnType(PsiType.VOID).addParameter("name", stringType).addParameter("oldValue", objectType).addParameter("newValue", objectType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "getPropertyChangeListeners").setMethodReturnType(pclArrayType));
    methods.add(new LightMethodBuilder(manager, GroovyLanguage.INSTANCE, "getPropertyChangeListeners").setMethodReturnType(pclArrayType).addParameter("name", stringType));
    for (LightMethodBuilder method : methods) {
        method.addModifier(PsiModifier.PUBLIC);
        method.setOriginInfo(ORIGIN_INFO);
        method.putUserData(DOCUMENTATION_DELEGATE_FQN, PCS_FQN);
    }
    context.addMethods(methods);
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) LightMethodBuilder(com.intellij.psi.impl.light.LightMethodBuilder)

Example 53 with GrTypeDefinition

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.

the class GroovyValidationUtil method validateVariableOccurrencesDown.

private static void validateVariableOccurrencesDown(PsiElement parent, PsiElement startChild, MultiMap<PsiElement, String> conflicts, @NotNull String varName) {
    PsiElement child = parent.getLastChild();
    while (child != null && child != startChild && !(child instanceof GrTypeDefinition)) {
        validateVariableOccurrencesDownImpl(child, conflicts, varName);
        child = child.getPrevSibling();
    }
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiElement(com.intellij.psi.PsiElement)

Example 54 with GrTypeDefinition

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.

the class GroovyOverrideMethodsHandler method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    if (!EditorModificationUtil.checkModificationAllowed(editor))
        return;
    PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, true);
    if (aClass instanceof GrTypeDefinition) {
        GrTypeDefinition typeDefinition = (GrTypeDefinition) aClass;
        if (GroovyOverrideImplementExploreUtil.getMethodSignaturesToOverride(typeDefinition).isEmpty()) {
            HintManager.getInstance().showErrorHint(editor, "No methods to override have been found");
            return;
        }
        GroovyOverrideImplementUtil.chooseAndOverrideMethods(project, editor, typeDefinition);
    }
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiClass(com.intellij.psi.PsiClass)

Example 55 with GrTypeDefinition

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition in project intellij-community by JetBrains.

the class TraitMethodImplementor method createImplementationPrototypes.

@NotNull
@Override
public PsiMethod[] createImplementationPrototypes(PsiClass inClass, PsiMethod method) throws IncorrectOperationException {
    if (!(inClass instanceof GrTypeDefinition && method instanceof GrTraitMethod))
        return PsiMethod.EMPTY_ARRAY;
    final PsiClass containingClass = method.getContainingClass();
    PsiSubstitutor substitutor = inClass.isInheritor(containingClass, true) ? TypeConversionUtil.getSuperClassSubstitutor(containingClass, inClass, PsiSubstitutor.EMPTY) : PsiSubstitutor.EMPTY;
    return new GrMethod[] { GroovyOverrideImplementUtil.generateTraitMethodPrototype((GrTypeDefinition) inClass, (GrTraitMethod) method, substitutor) };
}
Also used : GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition) PsiClass(com.intellij.psi.PsiClass) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) PsiSubstitutor(com.intellij.psi.PsiSubstitutor) GrTraitMethod(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrTraitMethod) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)78 PsiElement (com.intellij.psi.PsiElement)17 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)17 PsiClass (com.intellij.psi.PsiClass)16 NotNull (org.jetbrains.annotations.NotNull)15 Nullable (org.jetbrains.annotations.Nullable)14 GroovyFile (org.jetbrains.plugins.groovy.lang.psi.GroovyFile)9 PsiFile (com.intellij.psi.PsiFile)8 GroovyFileBase (org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase)8 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)8 GrField (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)8 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)8 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 Project (com.intellij.openapi.project.Project)6 ArrayList (java.util.ArrayList)6 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)6 Editor (com.intellij.openapi.editor.Editor)5 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4