当前位置: 首页>>代码示例>>Java>>正文


Java GenerateMembersUtil.suggestGetterName方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:16,代码来源:MethodNamePolicy.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:RemoveMiddlemanProcessor.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:ReplaceStaticVariableAccess.java

示例4: suggestGetterName

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入方法依赖的package包/类
@Override
@NotNull
public String suggestGetterName(@NotNull PsiField field) {
  return GenerateMembersUtil.suggestGetterName(field);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:JavaEncapsulateFieldHelper.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:ExtractedClassBuilder.java

示例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()));
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:62,代码来源:ExtractClassProcessor.java

示例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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:50,代码来源:InheritanceToDelegationProcessor.java

示例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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:77,代码来源:EncapsulateFieldsTest.java

示例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;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:51,代码来源:TypeMigrationLabeler.java


注:本文中的com.intellij.codeInsight.generation.GenerateMembersUtil.suggestGetterName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。