本文整理汇总了Java中com.intellij.codeInsight.generation.GenerateMembersUtil.suggestSetterName方法的典型用法代码示例。如果您正苦于以下问题:Java GenerateMembersUtil.suggestSetterName方法的具体用法?Java GenerateMembersUtil.suggestSetterName怎么用?Java GenerateMembersUtil.suggestSetterName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.generation.GenerateMembersUtil
的用法示例。
在下文中一共展示了GenerateMembersUtil.suggestSetterName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: suggestSetterName
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Override
@NotNull
public String suggestSetterName(@NotNull PsiField field) {
return GenerateMembersUtil.suggestSetterName(field);
}
示例2: findUsagesForField
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的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 = getQualifiedName();
@NonNls String getter = null;
if (myGenerateAccessors) {
getter = GenerateMembersUtil.suggestGetterName(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 = GenerateMembersUtil.suggestSetterName(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()));
}
}
}
示例3: doTest
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
private static void doTest(final PsiClass aClass,
final String conflicts,
final boolean generateGetters,
final boolean generateSetters,
final PsiField... fields) {
try {
final Project project = aClass.getProject();
EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
@Override
public FieldDescriptor[] getSelectedFields() {
final FieldDescriptor[] descriptors = new FieldDescriptor[fields.length];
for (int i = 0; i < fields.length; i++) {
descriptors[i] = new FieldDescriptorImpl(
fields[i],
GenerateMembersUtil.suggestGetterName(fields[i]),
GenerateMembersUtil.suggestSetterName(fields[i]),
isToEncapsulateGet() ? GenerateMembersUtil.generateGetterPrototype(fields[i]) : null,
isToEncapsulateSet() ? GenerateMembersUtil.generateSetterPrototype(fields[i]) : null
);
}
return descriptors;
}
@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;
}
@Override
public PsiClass getTargetClass() {
return aClass;
}
});
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);
}
}