本文整理汇总了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;
}
示例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();
}
示例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: 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();
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例12: getGetterName
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public String getGetterName() {
return PropertyUtil.suggestGetterName(myPropertyName, myPropertyType);
}
示例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);
}
示例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);
}
示例15: suggestGetterName
import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
@NotNull
public String suggestGetterName(@NotNull PsiField field) {
return PropertyUtil.suggestGetterName(field);
}