Search in sources :

Example 26 with GroovyPsiElementFactory

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.

the class GroovyIntroduceParameterObjectDelegate method createMergedParameterInfo.

@Override
public GrParameterInfo createMergedParameterInfo(GroovyIntroduceObjectClassDescriptor descriptor, GrMethod method, List<GrParameterInfo> oldMethodParameters) {
    final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(method.getProject());
    PsiType classType = elementFactory.createTypeByFQClassName(StringUtil.getQualifiedName(descriptor.getPackageName(), descriptor.getClassName()));
    return new GrParameterInfo(descriptor.getClassName(), null, null, classType, -1, false) {

        @Nullable
        @Override
        public PsiElement getActualValue(PsiElement callExpression, Object substitutor) {
            final IntroduceParameterObjectDelegate<PsiNamedElement, ParameterInfo, IntroduceParameterObjectClassDescriptor<PsiNamedElement, ParameterInfo>> delegate = findDelegate(callExpression);
            return delegate != null ? delegate.createNewParameterInitializerAtCallSite(callExpression, descriptor, oldMethodParameters, substitutor) : null;
        }
    };
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrParameterInfo(org.jetbrains.plugins.groovy.refactoring.changeSignature.GrParameterInfo) PsiNamedElement(com.intellij.psi.PsiNamedElement) IntroduceParameterObjectClassDescriptor(com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor) ParameterInfo(com.intellij.refactoring.changeSignature.ParameterInfo) GrParameterInfo(org.jetbrains.plugins.groovy.refactoring.changeSignature.GrParameterInfo) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Example 27 with GroovyPsiElementFactory

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.

the class GrPullUpHelper method doMoveField.

private void doMoveField(PsiSubstitutor substitutor, MemberInfo info) {
    GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(myProject);
    GrField field = (GrField) info.getMember();
    field.normalizeDeclaration();
    replaceMovedMemberTypeParameters(field, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
    fixReferencesToStatic(field);
    if (myTargetSuperClass.isInterface()) {
        PsiUtil.setModifierProperty(field, PsiModifier.PUBLIC, true);
    }
    final PsiMember movedElement = (PsiMember) myTargetSuperClass.add(convertFieldToLanguage(field, myTargetSuperClass.getLanguage()));
    myMembersAfterMove.add(movedElement);
    deleteMemberWithDocComment(field);
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField)

Example 28 with GroovyPsiElementFactory

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.

the class GrPullUpHelper method doMoveClass.

private void doMoveClass(PsiSubstitutor substitutor, MemberInfo info) {
    if (Boolean.FALSE.equals(info.getOverrides())) {
        PsiClass aClass = (PsiClass) info.getMember();
        if (myTargetSuperClass instanceof GrTypeDefinition) {
            addClassToSupers(info, aClass, substitutor, (GrTypeDefinition) myTargetSuperClass);
        }
    } else {
        GrTypeDefinition aClass = (GrTypeDefinition) info.getMember();
        GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(myProject);
        replaceMovedMemberTypeParameters(aClass, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
        fixReferencesToStatic(aClass);
        PsiMember movedElement = (PsiMember) myTargetSuperClass.addAfter(convertClassToLanguage(aClass, myTargetSuperClass.getLanguage()), null);
        myMembersAfterMove.add(movedElement);
        deleteMemberWithDocComment(aClass);
    }
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) GrTypeDefinition(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)

Example 29 with GroovyPsiElementFactory

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.

the class GrIntroduceClosureParameterProcessor method processInternalUsages.

private static void processInternalUsages(UsageInfo[] usages, GrIntroduceParameterSettings settings) {
    final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(settings.getProject());
    // Replacing expression occurrences
    for (UsageInfo usage : usages) {
        if (usage instanceof ChangedMethodCallInfo) {
            PsiElement element = usage.getElement();
            processChangedMethodCall(element, settings);
        } else if (usage instanceof InternalUsageInfo) {
            PsiElement element = usage.getElement();
            if (element == null)
                continue;
            GrExpression newExpr = factory.createExpressionFromText(settings.getName());
            if (element instanceof GrExpression) {
                ((GrExpression) element).replaceWithExpression(newExpr, true);
            } else {
                element.replace(newExpr);
            }
        }
    }
    final StringPartInfo info = settings.getStringPartInfo();
    if (info != null) {
        final GrExpression expr = info.replaceLiteralWithConcatenation(settings.getName());
        final Editor editor = PsiUtilBase.findEditor(expr);
        if (editor != null) {
            editor.getSelectionModel().removeSelection();
            editor.getCaretModel().moveToOffset(expr.getTextRange().getEndOffset());
        }
    }
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) ChangedMethodCallInfo(com.intellij.refactoring.introduceParameter.ChangedMethodCallInfo) Editor(com.intellij.openapi.editor.Editor) StringPartInfo(org.jetbrains.plugins.groovy.refactoring.introduce.StringPartInfo) ExternalUsageInfo(com.intellij.refactoring.introduceParameter.ExternalUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo) InternalUsageInfo(com.intellij.refactoring.introduceParameter.InternalUsageInfo) InternalUsageInfo(com.intellij.refactoring.introduceParameter.InternalUsageInfo)

Example 30 with GroovyPsiElementFactory

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory in project intellij-community by JetBrains.

the class GrVariableInplaceRenamer method renameSynthetic.

@Override
protected void renameSynthetic(String newName) {
    PsiNamedElement elementToRename = getVariable();
    if (elementToRename instanceof ClosureSyntheticParameter && !"it".equals(newName)) {
        final GrClosableBlock closure = ((ClosureSyntheticParameter) elementToRename).getClosure();
        final GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(myProject);
        final PsiType type = ((ClosureSyntheticParameter) elementToRename).getTypeGroovy();
        final GrParameter newParam = factory.createParameter(newName, TypesUtil.unboxPrimitiveTypeWrapper(type));
        final GrParameter added = closure.addParameter(newParam);
        JavaCodeStyleManager.getInstance(added.getProject()).shortenClassReferences(added);
    }
}
Also used : GroovyPsiElementFactory(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory) PsiNamedElement(com.intellij.psi.PsiNamedElement) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrParameter(org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter) ClosureSyntheticParameter(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.ClosureSyntheticParameter) PsiType(com.intellij.psi.PsiType)

Aggregations

GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)159 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)42 PsiElement (com.intellij.psi.PsiElement)30 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)23 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)22 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)21 IncorrectOperationException (com.intellij.util.IncorrectOperationException)20 Nullable (org.jetbrains.annotations.Nullable)20 GrParameter (org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter)18 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)18 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)17 NotNull (org.jetbrains.annotations.NotNull)16 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)15 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)14 Project (com.intellij.openapi.project.Project)8 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)8 ASTNode (com.intellij.lang.ASTNode)7 ArrayList (java.util.ArrayList)7 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)7 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)6