@Nullable public PsiType getPsiType() { final PsiElement element = resolve(); if (element instanceof VtlVariable) { return ((VtlVariable) element).getPsiType(); } if (element instanceof PsiMethod) { PsiMethod method = (PsiMethod) element; return getSubstitutedType(method, method.getReturnType()); } if (element instanceof BeanProperty) { final BeanProperty beanProperty = (BeanProperty) element; return getSubstitutedType(beanProperty.getMethod(), beanProperty.getPropertyType()); } return null; }
public static void doRename(@NotNull final BeanProperty property, final String newName, final boolean searchInComments, boolean isPreview) { final PsiElement psiElement = property.getPsiElement(); final RenameRefactoring rename = new JavaRenameRefactoringImpl(psiElement.getProject(), psiElement, newName, searchInComments, false); rename.setPreviewUsages(isPreview); final PsiMethod setter = property.getSetter(); if (setter != null) { final String setterName = PropertyUtil.suggestSetterName(newName); rename.addElement(setter, setterName); } final PsiMethod getter = property.getGetter(); if (getter != null) { final String getterName = PropertyUtil.suggestGetterName(newName, getter.getReturnType()); rename.addElement(getter, getterName); } rename.run(); }
public static void doRename(@NotNull final BeanProperty property, final String newName, final boolean searchInComments, boolean isPreview) { final PsiElement psiElement = property.getPsiElement(); final RenameRefactoring rename = new JavaRenameRefactoringImpl(psiElement.getProject(), psiElement, newName, searchInComments, false); rename.setPreviewUsages(isPreview); final PsiMethod setter = property.getSetter(); if (setter != null) { final String setterName = PropertyUtil.suggestSetterName(newName); rename.addElement(setter, setterName); final PsiParameter[] setterParameters = setter.getParameterList().getParameters(); if (setterParameters.length == 1) { final JavaCodeStyleManager manager = JavaCodeStyleManager.getInstance(psiElement.getProject()); final String suggestedParameterName = manager.propertyNameToVariableName(property.getName(), VariableKind.PARAMETER); if (suggestedParameterName.equals(setterParameters[0].getName())) { rename.addElement(setterParameters[0], manager.propertyNameToVariableName(newName, VariableKind.PARAMETER)); } } } final PsiMethod getter = property.getGetter(); if (getter != null) { final String getterName = PropertyUtil.suggestGetterName(newName, getter.getReturnType()); rename.addElement(getter, getterName); } rename.run(); }
@Nullable public static BeanProperty createVelocityStyleBeanProperty(@NotNull PsiMethod method, @Nullable String name) { if(name == null) { return null; } return VelocityNamingUtil.isPropertyAccessor(method) || VelocityNamingUtil.isGetByStringOrByObjectMethod(method) ? new VelocityStyleBeanProperty(method, name) : null; }
@Nullable protected abstract BeanProperty getProperty(DataContext context);
protected PropertyRenameDialog(BeanProperty property, final Editor editor) { super(property.getMethod().getProject(), property.getPsiElement(), null, editor); myProperty = property; }
private void performInvoke(@Nullable Editor editor, DataContext dataContext) { final BeanProperty property = getProperty(dataContext); new PropertyRenameDialog(property, editor).show(); }