本文整理汇总了Java中com.intellij.psi.util.PropertyUtil.suggestSetterName方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyUtil.suggestSetterName方法的具体用法?Java PropertyUtil.suggestSetterName怎么用?Java PropertyUtil.suggestSetterName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PropertyUtil
的用法示例。
在下文中一共展示了PropertyUtil.suggestSetterName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doRename
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
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();
}
示例2: findInstancePropertySetter
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Nullable
public static PsiMethod findInstancePropertySetter(@NotNull PsiClass psiClass,
@Nullable String propertyName) {
if (StringUtil.isEmpty(propertyName))
return null;
final String suggestedSetterName = PropertyUtil.suggestSetterName(propertyName);
final PsiMethod[] setters = psiClass.findMethodsByName(suggestedSetterName, true);
for (PsiMethod setter : setters) {
if (setter.hasModifierProperty(PUBLIC) && !setter.hasModifierProperty(STATIC)
&& isSimplePropertySetter(setter)) {
return setter;
}
}
return null;
}
示例3: getPropertiesHandlersNames
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private static String[] getPropertiesHandlersNames(final PsiClass psiClass,
final boolean staticContext,
final PsiType varType,
final PsiElement element) {
final List<String> propertyHandlers = new ArrayList<String>();
for (final PsiField field : psiClass.getFields()) {
if (field == element) continue;
if (StringUtil.isEmpty(field.getName())) continue;
PsiUtilCore.ensureValid(field);
PsiType fieldType = field.getType();
PsiUtil.ensureValidType(fieldType);
final PsiModifierList modifierList = field.getModifierList();
if (staticContext && (modifierList != null && !modifierList.hasModifierProperty(PsiModifier.STATIC))) continue;
if (fieldType.equals(varType)) {
final String getterName = PropertyUtil.suggestGetterName(field);
if ((psiClass.findMethodsByName(getterName, true).length == 0 ||
psiClass.findMethodBySignature(GenerateMembersUtil.generateGetterPrototype(field), true) == null)) {
propertyHandlers.add(getterName);
}
}
if (PsiType.VOID.equals(varType)) {
final String setterName = PropertyUtil.suggestSetterName(field);
if ((psiClass.findMethodsByName(setterName, true).length == 0 ||
psiClass.findMethodBySignature(GenerateMembersUtil.generateSetterPrototype(field), true) == null)) {
propertyHandlers.add(setterName);
}
}
}
return ArrayUtil.toStringArray(propertyHandlers);
}
示例4: checkTargetClasses
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
protected boolean checkTargetClasses(List<PsiClass> classes, String methodName) {
String propertyName = PropertyUtil.getPropertyName(methodName);
if (propertyName == null) return false;
String getterName = PropertyUtil.suggestGetterName(propertyName, null);
String setterName = PropertyUtil.suggestSetterName(propertyName);
for (PsiClass aClass : classes) {
if (aClass.findMethodsByName(getterName, false).length > 0 || aClass.findMethodsByName(setterName, false).length > 0) return false;
}
return true;
}
示例5: setName
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public void setName(String newName) throws IncorrectOperationException {
final PsiMethod setter = getSetter();
final PsiMethod getter = getGetter();
if (getter != null) {
final String getterName = PropertyUtil.suggestGetterName(newName, getter.getReturnType());
getter.setName(getterName);
}
if (setter != null) {
final String setterName = PropertyUtil.suggestSetterName(newName);
setter.setName(setterName);
}
}
示例6: createSetter
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
protected PsiElement createSetter(final boolean createField) throws IncorrectOperationException {
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myPsiClass.getProject()).getElementFactory();
final String methodName = PropertyUtil.suggestSetterName(myPropertyName);
final String typeName = myType.getCanonicalText();
@NonNls final String text;
boolean isInterface = myPsiClass.isInterface();
if (isInterface) {
text = "public void " + methodName + "(" + typeName + " " + myPropertyName + ");";
}
else if (createField) {
@NonNls String fieldName = getFieldName();
if (fieldName.equals(myPropertyName)) {
fieldName = "this." + fieldName;
}
text = "public void " + methodName + "(" + typeName + " " + myPropertyName + ") {" + fieldName + "=" + myPropertyName + ";}";
}
else {
text = "public void " + methodName + "(" + typeName + " " + myPropertyName + ") {}";
}
final PsiMethod method = elementFactory.createMethodFromText(text, null);
final PsiMethod psiElement = (PsiMethod)myPsiClass.add(method);
if (!isInterface && !createField) {
CreateFromUsageUtils.setupMethodBody(psiElement, myPsiClass);
}
return psiElement;
}
示例7: doRename
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
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();
}
示例8: getPropertiesHandlersNames
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private static String[] getPropertiesHandlersNames(final PsiClass psiClass,
final boolean staticContext,
final PsiType varType,
final PsiElement element) {
final List<String> propertyHandlers = new ArrayList<String>();
for (final PsiField field : psiClass.getFields()) {
if (field == element) continue;
PsiUtilCore.ensureValid(field);
PsiType fieldType = field.getType();
PsiUtil.ensureValidType(fieldType);
final PsiModifierList modifierList = field.getModifierList();
if (staticContext && (modifierList != null && !modifierList.hasModifierProperty(PsiModifier.STATIC))) continue;
if (fieldType.equals(varType)) {
final String getterName = PropertyUtil.suggestGetterName(field.getProject(), field);
if ((psiClass.findMethodsByName(getterName, true).length == 0 ||
psiClass.findMethodBySignature(PropertyUtil.generateGetterPrototype(field), true) == null)) {
propertyHandlers.add(getterName);
}
}
if (PsiType.VOID.equals(varType)) {
final String setterName = PropertyUtil.suggestSetterName(field.getProject(), field);
if ((psiClass.findMethodsByName(setterName, true).length == 0 ||
psiClass.findMethodBySignature(PropertyUtil.generateSetterPrototype(field), true) == null)) {
propertyHandlers.add(setterName);
}
}
}
return ArrayUtil.toStringArray(propertyHandlers);
}
示例9: EncapsulateFieldsDialog
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public EncapsulateFieldsDialog(Project project, PsiClass aClass, final Set preselectedFields) {
super(project, true);
myProject = project;
myClass = aClass;
String title = REFACTORING_NAME;
String qName = myClass.getQualifiedName();
if (qName != null) {
title += " - " + qName;
}
setTitle(title);
myFields = myClass.getFields();
myFieldNames = new String[myFields.length];
myCheckedMarks = new boolean[myFields.length];
myFinalMarks = new boolean[myFields.length];
myGetterNames = new String[myFields.length];
mySetterNames = new String[myFields.length];
myGetterPrototypes = new PsiMethod[myFields.length];
mySetterPrototypes = new PsiMethod[myFields.length];
for (int idx = 0; idx < myFields.length; idx++) {
PsiField field = myFields[idx];
myCheckedMarks[idx] = preselectedFields.contains(field);
myFinalMarks[idx] = field.hasModifierProperty(PsiModifier.FINAL);
myFieldNames[idx] =
PsiFormatUtil.formatVariable(field,
PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER,
PsiSubstitutor.EMPTY
);
myGetterNames[idx] = PropertyUtil.suggestGetterName(myProject, field);
mySetterNames[idx] = PropertyUtil.suggestSetterName(myProject, field);
myGetterPrototypes[idx] = generateMethodPrototype(field, myGetterNames[idx], true);
mySetterPrototypes[idx] = generateMethodPrototype(field, mySetterNames[idx], false);
}
init();
}
示例10: suggestSetterName
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public static String suggestSetterName(PsiField field) {
final PsiMethod prototype = generateSetterPrototype(field);
return prototype != null ? prototype.getName() : PropertyUtil.suggestSetterName(field);
}
示例11: suggestSetterName
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
@NotNull
public String suggestSetterName(@NotNull PsiField field) {
return PropertyUtil.suggestSetterName(field);
}
示例12: findUsagesForField
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private void findUsagesForField(PsiField field, List<FixableUsageInfo> usages) {
final PsiManager psiManager = field.getManager();
final Project project = psiManager.getProject();
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
final String qualifiedName = StringUtil.getQualifiedName(newPackageName, newClassName);
@NonNls String getter = null;
if (myGenerateAccessors) {
getter = PropertyUtil.suggestGetterName(myProject, field);
} else {
final PsiMethod fieldGetter = PropertyUtil.findPropertyGetter(sourceClass, field.getName(), false, false);
if (fieldGetter != null && isInMovedElement(fieldGetter)) {
getter = fieldGetter.getName();
}
}
@NonNls String setter = null;
if (myGenerateAccessors) {
setter = PropertyUtil.suggestSetterName(myProject, field);
} else {
final PsiMethod fieldSetter = PropertyUtil.findPropertySetter(sourceClass, field.getName(), false, false);
if (fieldSetter != null && isInMovedElement(fieldSetter)) {
setter = fieldSetter.getName();
}
}
final boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC);
for (PsiReference reference : ReferencesSearch.search(field, scope)) {
final PsiElement element = reference.getElement();
if (isInMovedElement(element)) {
continue;
}
if (element instanceof PsiReferenceExpression) {
final PsiReferenceExpression exp = (PsiReferenceExpression)element;
if (RefactoringUtil.isPlusPlusOrMinusMinus(exp.getParent())) {
usages.add(isStatic
? new ReplaceStaticVariableIncrementDecrement(exp, qualifiedName)
: new ReplaceInstanceVariableIncrementDecrement(exp, delegateFieldName, setter, getter, field.getName()));
}
else if (RefactoringUtil.isAssignmentLHS(exp)) {
usages.add(isStatic
? new ReplaceStaticVariableAssignment(exp, qualifiedName)
: new ReplaceInstanceVariableAssignment(PsiTreeUtil.getParentOfType(exp, PsiAssignmentExpression.class),
delegateFieldName, setter, getter, field.getName()));
}
else {
usages.add(isStatic
? new ReplaceStaticVariableAccess(exp, qualifiedName, enumConstants.contains(field))
: new ReplaceInstanceVariableAccess(exp, delegateFieldName, getter, field.getName()));
}
if (!isStatic) {
delegationRequired = true;
}
} else if (element instanceof PsiDocTagValue) {
usages.add(new BindJavadocReference(element, qualifiedName, field.getName()));
}
}
}
示例13: doTest
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private static void doTest(final PsiClass aClass, final PsiField field, final String conflicts,
final boolean generateGetters, final boolean generateSetters) {
try {
final Project project = aClass.getProject();
EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
@Override
public PsiField[] getSelectedFields() {
return new PsiField[]{field};
}
@Override
public String[] getGetterNames() {
return new String[]{PropertyUtil.suggestGetterName(project, field)};
}
@Override
public String[] getSetterNames() {
return new String[]{PropertyUtil.suggestSetterName(project, field)};
}
@Override
@Nullable
public PsiMethod[] getGetterPrototypes() {
return isToEncapsulateGet() ? new PsiMethod[]{PropertyUtil.generateGetterPrototype(field)} : null;
}
@Override
@Nullable
public PsiMethod[] getSetterPrototypes() {
return isToEncapsulateSet() ? new PsiMethod[]{PropertyUtil.generateSetterPrototype(field)} : null;
}
@Override
public boolean isToEncapsulateGet() {
return generateGetters;
}
@Override
public boolean isToEncapsulateSet() {
return generateSetters;
}
@Override
public boolean isToUseAccessorsWhenAccessible() {
return true;
}
@Override
public String getFieldsVisibility() {
return null;
}
@Override
public String getAccessorsVisibility() {
return PsiModifier.PUBLIC;
}
@Override
public int getJavadocPolicy() {
return DocCommentPolicy.MOVE;
}
});
processor.run();
LocalFileSystem.getInstance().refresh(false);
FileDocumentManager.getInstance().saveAllDocuments();
}
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
if (conflicts != null) {
Assert.assertEquals(conflicts, e.getMessage());
return;
} else {
e.printStackTrace();
fail(e.getMessage());
}
}
if (conflicts != null) {
fail("Conflicts were not detected: " + conflicts);
}
}
示例14: getPropertiesHandlersNames
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private static String[] getPropertiesHandlersNames(final PsiClass psiClass, final boolean staticContext, final PsiType varType, final PsiElement element)
{
final List<String> propertyHandlers = new ArrayList<>();
for(final PsiField field : psiClass.getFields())
{
if(field == element)
{
continue;
}
if(StringUtil.isEmpty(field.getName()))
{
continue;
}
PsiUtilCore.ensureValid(field);
PsiType fieldType = field.getType();
PsiUtil.ensureValidType(fieldType);
final PsiModifierList modifierList = field.getModifierList();
if(staticContext && (modifierList != null && !modifierList.hasModifierProperty(PsiModifier.STATIC)))
{
continue;
}
if(fieldType.equals(varType))
{
final String getterName = PropertyUtil.suggestGetterName(field);
if((psiClass.findMethodsByName(getterName, true).length == 0 || psiClass.findMethodBySignature(GenerateMembersUtil.generateGetterPrototype(field), true) == null))
{
propertyHandlers.add(getterName);
}
}
if(PsiType.VOID.equals(varType))
{
final String setterName = PropertyUtil.suggestSetterName(field);
if((psiClass.findMethodsByName(setterName, true).length == 0 || psiClass.findMethodBySignature(GenerateMembersUtil.generateSetterPrototype(field), true) == null))
{
propertyHandlers.add(setterName);
}
}
}
return ArrayUtil.toStringArray(propertyHandlers);
}
示例15: suggestSetterName
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public static String suggestSetterName(PsiField field)
{
final PsiMethod prototype = generateSetterPrototype(field);
return prototype != null ? prototype.getName() : PropertyUtil.suggestSetterName(field);
}