Search in sources :

Example 1 with IntroduceParameterObjectClassDescriptor

use of com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor 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 2 with IntroduceParameterObjectClassDescriptor

use of com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor in project intellij-community by JetBrains.

the class IntroduceParameterObjectAction method getHandler.

protected RefactoringActionHandler getHandler(@NotNull DataContext context) {
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
    if (element == null) {
        return null;
    }
    final IntroduceParameterObjectDelegate<PsiNamedElement, ParameterInfo, IntroduceParameterObjectClassDescriptor<PsiNamedElement, ParameterInfo>> delegate = IntroduceParameterObjectDelegate.findDelegate(element);
    return delegate != null ? delegate.getHandler(element) : null;
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) IntroduceParameterObjectClassDescriptor(com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor) ParameterInfo(com.intellij.refactoring.changeSignature.ParameterInfo) PsiElement(com.intellij.psi.PsiElement)

Example 3 with IntroduceParameterObjectClassDescriptor

use of com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor in project intellij-community by JetBrains.

the class JavaIntroduceParameterObjectDelegate method createMergedParameterInfo.

@Override
public ParameterInfoImpl createMergedParameterInfo(JavaIntroduceParameterObjectClassDescriptor descriptor, PsiMethod method, List<ParameterInfoImpl> oldMethodParameters) {
    final PsiCodeBlock body = method.getBody();
    String baseParameterName = StringUtil.decapitalize(descriptor.getClassName());
    final Project project = method.getProject();
    if (!PsiNameHelper.getInstance(project).isIdentifier(baseParameterName, LanguageLevel.HIGHEST)) {
        baseParameterName = StringUtil.fixVariableNameDerivedFromPropertyName(baseParameterName);
    }
    final String paramName = body != null ? JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(baseParameterName, body.getLBrace(), true) : JavaCodeStyleManager.getInstance(project).propertyNameToVariableName(baseParameterName, VariableKind.PARAMETER);
    final String classTypeText = descriptor.createFakeClassTypeText();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    return new ParameterInfoImpl(-1, paramName, facade.getElementFactory().createTypeFromText(classTypeText, method), null) {

        @Nullable
        @Override
        public PsiElement getActualValue(PsiElement exp, Object substitutor) {
            final IntroduceParameterObjectDelegate<PsiNamedElement, ParameterInfo, IntroduceParameterObjectClassDescriptor<PsiNamedElement, ParameterInfo>> delegate = findDelegate(exp);
            return delegate != null ? delegate.createNewParameterInitializerAtCallSite(exp, descriptor, oldMethodParameters, substitutor) : null;
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) IntroduceParameterObjectClassDescriptor(com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor)

Aggregations

IntroduceParameterObjectClassDescriptor (com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor)3 PsiElement (com.intellij.psi.PsiElement)2 PsiNamedElement (com.intellij.psi.PsiNamedElement)2 ParameterInfo (com.intellij.refactoring.changeSignature.ParameterInfo)2 Project (com.intellij.openapi.project.Project)1 PsiType (com.intellij.psi.PsiType)1 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)1 GrParameterInfo (org.jetbrains.plugins.groovy.refactoring.changeSignature.GrParameterInfo)1