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;
}
};
}
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);
}
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);
}
}
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());
}
}
}
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);
}
}
Aggregations