本文整理汇总了Java中com.intellij.codeInsight.generation.GenerateMembersUtil.suggestGetterName方法的典型用法代码示例。如果您正苦于以下问题:Java GenerateMembersUtil.suggestGetterName方法的具体用法?Java GenerateMembersUtil.suggestGetterName怎么用?Java GenerateMembersUtil.suggestGetterName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.codeInsight.generation.GenerateMembersUtil
的用法示例。
在下文中一共展示了GenerateMembersUtil.suggestGetterName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Nonnull
@Override
public String convert(@Nonnull String name, @Nonnull TypeName type) {
final String variableName = DefaultNamePolicy.format(name, CaseFormat.UPPER_CAMEL);
if (Strings.isNullOrEmpty(variableName)) {
throw new IllegalArgumentException("Cannot convert '" + name + "' to a method name");
}
try {
final PsiType psiType = typeConverter.apply(type);
return GenerateMembersUtil.suggestGetterName(variableName, psiType, project);
} catch (IncorrectOperationException e) {
throw new IllegalArgumentException("Cannot convert '" + name + "' to a method name", e);
}
}
示例2: findUsages
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
public void findUsages(@NotNull List<FixableUsageInfo> usages) {
for (final MemberInfo memberInfo : myDelegateMethodInfos) {
if (!memberInfo.isChecked()) continue;
final PsiMethod method = (PsiMethod)memberInfo.getMember();
final String getterName = GenerateMembersUtil.suggestGetterName(field);
final int[] paramPermutation = DelegationUtils.getParameterPermutation(method);
final PsiMethod delegatedMethod = DelegationUtils.getDelegatedMethod(method);
LOG.assertTrue(!DelegationUtils.isAbstract(method));
processUsagesForMethod(memberInfo.isToAbstract(), method, paramPermutation, getterName, delegatedMethod, usages);
}
}
示例3: fixUsage
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
public void fixUsage() throws IncorrectOperationException {
if (myEnumConstant) {
final PsiSwitchLabelStatement switchStatement = PsiTreeUtil.getParentOfType(expression, PsiSwitchLabelStatement.class);
if (switchStatement != null) {
MutationUtils.replaceExpression(expression.getReferenceName(), expression);
return;
}
}
final boolean replaceWithGetEnumValue = myEnumConstant && !alreadyMigratedToEnum();
final String link = replaceWithGetEnumValue ? "." + GenerateMembersUtil.suggestGetterName("value", expression.getType(), expression.getProject()) + "()" : "";
MutationUtils.replaceExpression(delegateClass + '.' + expression.getReferenceName() + link, expression);
}
示例4: suggestGetterName
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Override
@NotNull
public String suggestGetterName(@NotNull PsiField field) {
return GenerateMembersUtil.suggestGetterName(field);
}
示例5: getterName
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
private String getterName() {//todo unique getterName: see also com.intellij.refactoring.extractclass.usageInfo.ReplaceStaticVariableAccess
return GenerateMembersUtil.suggestGetterName("value", myEnumParameterType, myProject);
}
示例6: 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()));
}
}
}
示例7: InheritanceToDelegationProcessor
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
public InheritanceToDelegationProcessor(Project project,
PsiClass aClass,
@NotNull PsiClass targetBaseClass,
String fieldName,
String innerClassName,
PsiClass[] delegatedInterfaces,
PsiMethod[] delegatedMethods,
boolean delegateOtherMembers,
boolean generateGetter) {
super(project);
myClass = aClass;
myInnerClassName = innerClassName;
myIsDelegateOtherMembers = delegateOtherMembers;
myManager = myClass.getManager();
myFactory = JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory();
myBaseClass = targetBaseClass;
LOG.assertTrue(
// && !myBaseClass.isInterface()
myBaseClass.getQualifiedName() == null || !myBaseClass.getQualifiedName().equals(CommonClassNames.JAVA_LANG_OBJECT), myBaseClass);
myBaseClassMembers = getAllBaseClassMembers();
myBaseClassBases = getAllBases();
myBaseClassType = myFactory.createType(myBaseClass, getSuperSubstitutor (myBaseClass));
myIsInnerClassNeeded = InheritanceToDelegationUtil.isInnerClassNeeded(myClass, myBaseClass);
myFieldName = fieldName;
final String propertyName = JavaCodeStyleManager.getInstance(myProject).variableNameToPropertyName(myFieldName, VariableKind.FIELD);
myGetterName = GenerateMembersUtil.suggestGetterName(propertyName, myBaseClassType, myProject);
myGenerateGetter = generateGetter;
myDelegatedInterfaces = new LinkedHashSet<PsiClass>();
addAll(myDelegatedInterfaces, delegatedInterfaces);
myDelegatedMethods = new LinkedHashSet<PsiMethod>();
addAll(myDelegatedMethods, delegatedMethods);
myDelegatedMethodsVisibility = new HashMap<PsiMethod, String>();
for (PsiMethod method : myDelegatedMethods) {
MethodSignature signature = method.getSignature(getSuperSubstitutor(method.getContainingClass()));
PsiMethod overridingMethod = MethodSignatureUtil.findMethodBySignature(myClass, signature, false);
if (overridingMethod != null) {
myDelegatedMethodsVisibility.put(method,
VisibilityUtil.getVisibilityModifier(overridingMethod.getModifierList()));
}
}
myOverriddenMethods = getOverriddenMethods();
}
示例8: 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);
}
}
示例9: isMethodNameCanBeChanged
import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Nullable
private String isMethodNameCanBeChanged(PsiMethod method)
{
if(myCurrentRoot == null)
{
return null;
}
final PsiElement root = myCurrentRoot.getElement();
if(!(root instanceof PsiField))
{
return null;
}
PsiField field = (PsiField) root;
final PsiType migrationType = myTypeEvaluator.getType(root);
if(migrationType == null)
{
return null;
}
final PsiType sourceType = field.getType();
if(TypeConversionUtil.isAssignable(migrationType, sourceType))
{
return null;
}
if(!(migrationType.equals(PsiType.BOOLEAN) || migrationType.equals(PsiType.BOOLEAN.getBoxedType(field))) && !(sourceType.equals(PsiType.BOOLEAN) || sourceType.equals(PsiType.BOOLEAN
.getBoxedType(field))))
{
return null;
}
final PsiMethod[] getters = GetterSetterPrototypeProvider.findGetters(field.getContainingClass(), field.getName(), field.hasModifierProperty(PsiModifier.STATIC));
if(getters != null)
{
for(PsiMethod getter : getters)
{
if(getter.isEquivalentTo(method))
{
final String suggestedName = GenerateMembersUtil.suggestGetterName(field.getName(), migrationType, method.getProject());
if(!suggestedName.equals(method.getName()))
{
if(getter.getContainingClass().findMethodsByName(suggestedName, true).length != 0)
{
return null;
}
return suggestedName;
}
return null;
}
}
}
return null;
}