use of com.intellij.psi.PsiType 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);
}
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class GrInplaceVariableIntroducer method addAdditionalVariables.
@Override
protected void addAdditionalVariables(TemplateBuilderImpl builder) {
GrVariable variable = getVariable();
assert variable != null && variable.getInitializerGroovy() != null;
final PsiType initializerType = variable.getInitializerGroovy().getType();
TypeConstraint[] constraints = initializerType != null && !initializerType.equals(PsiType.NULL) ? new SupertypeConstraint[] { SupertypeConstraint.create(initializerType) } : TypeConstraint.EMPTY_ARRAY;
ChooseTypeExpression typeExpression = new ChooseTypeExpression(constraints, variable.getManager(), variable.getResolveScope(), true, GroovyApplicationSettings.getInstance().INTRODUCE_LOCAL_SELECT_DEF);
PsiElement element = getTypeELementOrDef(variable);
if (element == null)
return;
builder.replaceElement(element, "Variable_type", typeExpression, true, true);
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class CreateParameterFromUsageFix method showDialog.
private static void showDialog(final PsiMethod method, final GrReferenceExpression ref, final Project project) {
final String name = ref.getReferenceName();
final List<PsiType> types = GroovyExpectedTypesProvider.getDefaultExpectedTypes(ref);
PsiType unboxed = types.isEmpty() ? null : TypesUtil.unboxPrimitiveTypeWrapper(types.get(0));
@NotNull final PsiType type = unboxed != null ? unboxed : PsiType.getJavaLangObject(ref.getManager(), ref.getResolveScope());
if (method instanceof GrMethod) {
GrMethodDescriptor descriptor = new GrMethodDescriptor((GrMethod) method);
GrChangeSignatureDialog dialog = new GrChangeSignatureDialog(project, descriptor, true, ref);
List<GrParameterInfo> parameters = dialog.getParameters();
parameters.add(createParameterInfo(name, type));
dialog.setParameterInfos(parameters);
dialog.show();
} else if (method != null) {
JavaChangeSignatureDialog dialog = new JavaChangeSignatureDialog(project, method, false, ref);
final List<ParameterInfoImpl> parameterInfos = new ArrayList<>(Arrays.asList(ParameterInfoImpl.fromMethod(method)));
ParameterInfoImpl parameterInfo = new ParameterInfoImpl(-1, name, type, PsiTypesUtil.getDefaultValueOfType(type), false);
if (!method.isVarArgs()) {
parameterInfos.add(parameterInfo);
} else {
parameterInfos.add(parameterInfos.size() - 1, parameterInfo);
}
dialog.setParameterInfos(parameterInfos);
dialog.show();
}
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class CreateSetterFromUsageFix method getArgumentTypes.
@Override
protected PsiType[] getArgumentTypes() {
final GrReferenceExpression ref = getRefExpr();
assert PsiUtil.isLValue(ref);
PsiType initializer = TypeInferenceHelper.getInitializerTypeFor(ref);
if (initializer == null || initializer == PsiType.NULL) {
initializer = TypesUtil.getJavaLangObject(ref);
}
return new PsiType[] { initializer };
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class ConvertSimpleGetterToPropertyIntention method processIntention.
@Override
protected void processIntention(@NotNull PsiElement element, @NotNull Project project, Editor editor) throws IncorrectOperationException {
GrMethod method = (GrMethod) element.getParent();
GrOpenBlock block = method.getBlock();
if (block == null)
return;
GrStatement statement = block.getStatements()[0];
GrExpression value;
if (statement instanceof GrReturnStatement) {
value = ((GrReturnStatement) statement).getReturnValue();
} else {
value = (GrExpression) statement;
}
String fieldName = GroovyPropertyUtils.getPropertyNameByGetter(method);
if (fieldName == null)
return;
PsiClass aClass = method.getContainingClass();
if (aClass == null)
return;
List<String> modifiers = ContainerUtil.newArrayList();
for (String modifier : MODIFIERS_TO_CHECK) {
if (method.hasModifierProperty(modifier))
modifiers.add(modifier);
}
modifiers.add(PsiModifier.FINAL);
GrTypeElement returnTypeElement = method.getReturnTypeElementGroovy();
PsiType returnType = returnTypeElement == null ? null : returnTypeElement.getType();
GrVariableDeclaration declaration = GroovyPsiElementFactory.getInstance(project).createFieldDeclaration(ArrayUtil.toStringArray(modifiers), fieldName, value, returnType);
PsiElement replaced = method.replace(declaration);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(replaced);
}
Aggregations