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


Java PropertyUtil.generateSetterPrototype方法代码示例

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


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

示例1: registerQuickFix

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public static void registerQuickFix(PsiMember refElement,
                                    PsiJavaCodeReferenceElement place,
                                    PsiClass accessObjectClass,
                                    HighlightInfo error) {
  if (refElement instanceof PsiField && place instanceof PsiReferenceExpression) {
    final PsiField psiField = (PsiField)refElement;
    final PsiClass containingClass = psiField.getContainingClass();
    if (containingClass != null) {
      if (PsiUtil.isOnAssignmentLeftHand((PsiExpression)place)) {
        final PsiMethod setterPrototype = PropertyUtil.generateSetterPrototype(psiField);
        final PsiMethod setter = containingClass.findMethodBySignature(setterPrototype, true);
        if (setter != null && PsiUtil.isAccessible(setter, place, accessObjectClass)) {
          QuickFixAction.registerQuickFixAction(error, new ReplaceInaccessibleFieldWithGetterSetterFix(place, setter, true));
        }
      }
      else if (PsiUtil.isAccessedForReading((PsiExpression)place)) {
        final PsiMethod getterPrototype = GenerateMembersUtil.generateGetterPrototype(psiField);
        final PsiMethod getter = containingClass.findMethodBySignature(getterPrototype, true);
        if (getter != null && PsiUtil.isAccessible(getter, place, accessObjectClass)) {
          QuickFixAction.registerQuickFixAction(error, new ReplaceInaccessibleFieldWithGetterSetterFix(place, getter, false));
        }
      }
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:26,代码来源:ReplaceInaccessibleFieldWithGetterSetterFix.java

示例2: generateSetters

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
public PsiMethod[] generateSetters(PsiField field) {
  final PsiMethod setter = PropertyUtil.generateSetterPrototype(field);
  final Project project = field.getProject();

  final PsiType wrappedType = JavaFxPsiUtil.getWrappedPropertyType(field, project, JavaFxCommonClassNames.ourWritableMap);
  
  final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
  final PsiTypeElement newTypeElement = elementFactory.createTypeElement(wrappedType);
  final PsiParameter[] parameters = setter.getParameterList().getParameters();
  LOG.assertTrue(parameters.length == 1);
  final PsiParameter parameter = parameters[0];
  final PsiTypeElement typeElement = parameter.getTypeElement();
  LOG.assertTrue(typeElement != null);
  typeElement.replace(newTypeElement);
  final PsiCodeBlock body = setter.getBody();
  LOG.assertTrue(body != null);
  body.getStatements()[0].replace(elementFactory.createStatementFromText("this." + field.getName() + ".set(" + parameter.getName() + ");", field));

  return new PsiMethod[] {setter};
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:JavaFxGetterSetterPrototypeProvider.java

示例3: generateGetterSetters

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public static PsiMethod[] generateGetterSetters(PsiField field, boolean generateGetter) {
  for (GetterSetterPrototypeProvider provider : Extensions.getExtensions(EP_NAME)) {
    if (provider.canGeneratePrototypeFor(field)) {
      return generateGetter ? provider.generateGetters(field) : provider.generateSetters(field);
    }
  }
  return new PsiMethod[] {generateGetter ? PropertyUtil.generateGetterPrototype(field) : PropertyUtil.generateSetterPrototype(field)};
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:9,代码来源:GetterSetterPrototypeProvider.java

示例4: generateConstructor

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private PsiMethod generateConstructor(final PsiClass targetClass, final PsiType builderType) {
    final PsiMethod constructor = psiElementFactory.createConstructor(targetClass.getName());
    constructor.getModifierList().setModifierProperty(PsiModifier.PRIVATE, true);

    final PsiParameter builderParameter = psiElementFactory.createParameter("builder", builderType);
    constructor.getParameterList().add(builderParameter);

    final PsiCodeBlock constructorBody = constructor.getBody();
    if (constructorBody != null) {
        for (final PsiFieldMember member : selectedFields) {
            final PsiField field = member.getElement();

            final PsiMethod setterPrototype = PropertyUtil.generateSetterPrototype(field);
            final PsiMethod setter = targetClass.findMethodBySignature(setterPrototype, true);

            final String fieldName = field.getName();
            boolean isFinal = false;
            final PsiModifierList modifierList = field.getModifierList();
            if (modifierList != null) {
                isFinal = modifierList.hasModifierProperty(PsiModifier.FINAL);
            }

            final String assignText;
            if (setter == null || isFinal) {
                assignText = String.format("%1$s = builder.%1$s;", fieldName);
            } else {
                assignText = String.format("%s(builder.%s);", setter.getName(), fieldName);
            }

            final PsiStatement assignStatement = psiElementFactory.createStatementFromText(assignText, null);
            constructorBody.add(assignStatement);
        }
    }

    return constructor;
}
 
开发者ID:analytically,项目名称:innerbuilder,代码行数:37,代码来源:InnerBuilderGenerator.java

示例5: beforeTemplateFinished

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
protected void beforeTemplateFinished(PsiClass aClass, PsiField field) {
  PsiMethod getterPrototype = PropertyUtil.generateGetterPrototype(field);
  if (aClass.findMethodsBySignature(getterPrototype, false).length == 0) {
    aClass.add(getterPrototype);
  }


  PsiMethod setterPrototype = PropertyUtil.generateSetterPrototype(field);
  if (aClass.findMethodsBySignature(setterPrototype, false).length == 0) {
    aClass.add(setterPrototype);
  }
  
  super.beforeTemplateFinished(aClass, field);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:16,代码来源:CreateGetterSetterPropertyFromUsageFix.java

示例6: doTest

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private static void doTest(final PsiClass aClass, final PsiField field, final String conflicts,
                           final boolean generateGetters, final boolean  generateSetters) {
  try {
    final Project project = aClass.getProject();
    EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
      @Override
      public PsiField[] getSelectedFields() {
        return new PsiField[]{field};
      }

      @Override
      public String[] getGetterNames() {
        return new String[]{PropertyUtil.suggestGetterName(project, field)};
      }

      @Override
      public String[] getSetterNames() {
        return new String[]{PropertyUtil.suggestSetterName(project, field)};
      }

      @Override
      @Nullable
      public PsiMethod[] getGetterPrototypes() {
        return isToEncapsulateGet() ? new PsiMethod[]{PropertyUtil.generateGetterPrototype(field)} : null;
      }

      @Override
      @Nullable
      public PsiMethod[] getSetterPrototypes() {
        return isToEncapsulateSet() ? new PsiMethod[]{PropertyUtil.generateSetterPrototype(field)} : null;
      }

      @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;
      }
    });
    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:lshain-android-source,项目名称:tools-idea,代码行数:80,代码来源:EncapsulateFieldsTest.java

示例7: doTest

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private static void doTest(final PsiClass aClass,
                           final PsiField field,
                           final String conflicts,
                           final boolean generateGetters,
                           final boolean generateSetters) {
  try {
    final Project project = aClass.getProject();
    EncapsulateFieldsProcessor processor = new EncapsulateFieldsProcessor(project, new EncapsulateFieldsDescriptor() {
      @Override
      public FieldDescriptor[] getSelectedFields() {
        return new FieldDescriptor[]{new FieldDescriptorImpl(
          field,
          PropertyUtil.suggestGetterName(field),
          PropertyUtil.suggestSetterName(field),
          isToEncapsulateGet() ? PropertyUtil.generateGetterPrototype(field) : null,
          isToEncapsulateSet() ? PropertyUtil.generateSetterPrototype(field) : null
        )};
      }

      @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:consulo,项目名称:consulo-java,代码行数:73,代码来源:EncapsulateFieldsTest.java


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