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


Java PropertyUtil.suggestGetterName方法代码示例

本文整理汇总了Java中com.intellij.psi.util.PropertyUtil.suggestGetterName方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyUtil.suggestGetterName方法的具体用法?Java PropertyUtil.suggestGetterName怎么用?Java PropertyUtil.suggestGetterName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.PropertyUtil的用法示例。


在下文中一共展示了PropertyUtil.suggestGetterName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createGetter

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
protected PsiElement createGetter(final boolean createField) throws IncorrectOperationException {
  final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myPsiClass.getProject()).getElementFactory();
  final String methodName = PropertyUtil.suggestGetterName(myPropertyName, myType);
  final String typeName = myType.getCanonicalText();
  @NonNls final String text;
  boolean isInterface = myPsiClass.isInterface();
  if (createField) {
    final String fieldName = getFieldName();
    text = "public " + typeName + " " + methodName + "() { return " + fieldName + "; }";
  } else {
    if (isInterface) {
      text = typeName + " " + methodName + "();";
    }
    else {
      text = "public " + typeName + " " + methodName + "() { return null; }";
    }
  }
  final PsiMethod method = elementFactory.createMethodFromText(text, null);
  final PsiMethod psiElement = (PsiMethod)myPsiClass.add(method);
  if (!createField && !isInterface) {
    CreateFromUsageUtils.setupMethodBody(psiElement);
  }
  return psiElement;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:CreateBeanPropertyFix.java

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

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

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

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

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

示例7: 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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:36,代码来源:JavaMemberNameCompletionContributor.java

示例8: 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();
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:38,代码来源:EncapsulateFieldsDialog.java

示例9: findUsages

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public void findUsages(@NotNull List<FixableUsageInfo> usages) {
  for (final MemberInfo memberInfo : myDelegateMethodInfos) {
    if (!memberInfo.isChecked()) continue;
    final PsiMethod method = (PsiMethod)memberInfo.getMember();
    final Project project = method.getProject();
    final String getterName = PropertyUtil.suggestGetterName(project, 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:lshain-android-source,项目名称:tools-idea,代码行数:13,代码来源:RemoveMiddlemanProcessor.java

示例10: fixUsage

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的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 ? "." + PropertyUtil.suggestGetterName("value", expression.getType()) + "()" : "";
  MutationUtils.replaceExpression(delegateClass + '.' + expression.getReferenceName() + link, expression);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:13,代码来源:ReplaceStaticVariableAccess.java

示例11: findUsages

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public void findUsages(@NotNull List<FixableUsageInfo> usages) {
  for (final MemberInfo memberInfo : myDelegateMethodInfos) {
    if (!memberInfo.isChecked()) continue;
    final PsiMethod method = (PsiMethod)memberInfo.getMember();
    final Project project = method.getProject();
    final String getterName = PropertyUtil.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:consulo,项目名称:consulo-java,代码行数:13,代码来源:RemoveMiddlemanProcessor.java

示例12: getGetterName

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public String getGetterName() {
  return PropertyUtil.suggestGetterName(myPropertyName, myPropertyType);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:PropertyGroup.java

示例13: suggestGetterName

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public static String suggestGetterName(PsiField field) {
  final PsiMethod prototype = generateGetterPrototype(field);
  return prototype != null ? prototype.getName() : PropertyUtil.suggestGetterName(field);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:GenerateMembersUtil.java

示例14: suggestGetterName

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@SuppressWarnings({"HardCodedStringLiteral"})
private static String suggestGetterName(final String propertyName, final String propertyType) {
  return PropertyUtil.suggestGetterName(propertyName, "boolean".equals(propertyType) ? PsiType.BOOLEAN : null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:Generator.java

示例15: suggestGetterName

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


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