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


Java PropertyUtil.generateGetterPrototype方法代码示例

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


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

示例1: generateGetters

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
public PsiMethod[] generateGetters(PsiField field) {
  final Project project = field.getProject();
  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
  final PsiMethod getter = GenerateMembersUtil.generateSimpleGetterPrototype(field);

  final PsiType wrappedType = JavaFxPsiUtil.getWrappedPropertyType(field, project, JavaFxCommonClassNames.ourReadOnlyMap);

  final PsiTypeElement returnTypeElement = getter.getReturnTypeElement();
  LOG.assertTrue(returnTypeElement != null);
  returnTypeElement.replace(factory.createTypeElement(wrappedType));

  final PsiCodeBlock getterBody = getter.getBody();
  LOG.assertTrue(getterBody != null);
  getterBody.getStatements()[0].replace(factory.createStatementFromText("return " + field.getName() + ".get();", field));

  final PsiMethod propertyGetter = PropertyUtil.generateGetterPrototype(field);
  propertyGetter.setName(JavaCodeStyleManager.getInstance(project).variableNameToPropertyName(field.getName(), VariableKind.FIELD) + "Property");
  return new PsiMethod[] {getter, GenerateMembersUtil.annotateOnOverrideImplement(field.getContainingClass(), propertyGetter)};
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:JavaFxGetterSetterPrototypeProvider.java

示例2: anyFieldsWithGettersPresent

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
public static boolean anyFieldsWithGettersPresent(List<UsageInfo> classMemberRefs) {
  for (UsageInfo usageInfo : classMemberRefs) {

    if (usageInfo.getElement() instanceof PsiReferenceExpression) {
      PsiElement e = ((PsiReferenceExpression)usageInfo.getElement()).resolve();

      if (e instanceof PsiField) {
        PsiField psiField = (PsiField)e;
        PsiMethod getterPrototype = PropertyUtil.generateGetterPrototype(psiField);

        PsiMethod getter = psiField.getContainingClass().findMethodBySignature(getterPrototype, true);

        if (getter != null) return true;
      }
    }
  }

  return false;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:Util.java

示例3: generateGetters

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
@Override
public PsiMethod[] generateGetters(PsiField field) {
  final Project project = field.getProject();
  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
  final PsiMethod getter = PropertyUtil.generateGetterPrototype(field);

  final PsiType wrappedType = JavaFxPsiUtil.getWrappedPropertyType(field, project, JavaFxCommonClassNames.ourReadOnlyMap);

  final PsiTypeElement returnTypeElement = getter.getReturnTypeElement();
  LOG.assertTrue(returnTypeElement != null);
  returnTypeElement.replace(factory.createTypeElement(wrappedType));

  final PsiCodeBlock getterBody = getter.getBody();
  LOG.assertTrue(getterBody != null);
  getterBody.getStatements()[0].replace(factory.createStatementFromText("return " + field.getName() + ".get();", field));

  final PsiMethod propertyGetter = PropertyUtil.generateGetterPrototype(field);
  propertyGetter.setName(JavaCodeStyleManager.getInstance(project).variableNameToPropertyName(field.getName(), VariableKind.FIELD) + "Property");
  return new PsiMethod[] {getter, propertyGetter};
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:JavaFxGetterSetterPrototypeProvider.java

示例4: 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

示例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: replaceFieldWithGetter

import com.intellij.psi.util.PropertyUtil; //导入方法依赖的package包/类
private PsiElement replaceFieldWithGetter(PsiElement expr, PsiField psiField, boolean qualify) throws IncorrectOperationException {
  if (RefactoringUtil.isAssignmentLHS(expr)) {
    // todo: warning
    return expr;
  }
  PsiElement newExpr = expr;

  PsiMethod getterPrototype = PropertyUtil.generateGetterPrototype(psiField);

  PsiMethod getter = psiField.getContainingClass().findMethodBySignature(getterPrototype, true);

  if (getter != null) {

    if (JavaPsiFacade.getInstance(psiField.getProject()).getResolveHelper().isAccessible(getter, newExpr, null)) {
      PsiElementFactory factory = JavaPsiFacade.getInstance(newExpr.getProject()).getElementFactory();
      String id = getter.getName();
      String qualifier = null;
      if (newExpr instanceof PsiReferenceExpression) {
        final PsiExpression instanceRef = getInstanceRef(factory);
        if (qualify && instanceRef != null) {
          qualifier = instanceRef.getText();
        } else {
          final PsiExpression qualifierExpression = ((PsiReferenceExpression)newExpr).getQualifierExpression();
          if (qualifierExpression != null) {
            qualifier = qualifierExpression.getText();
          }
        }
      }
      PsiMethodCallExpression getterCall =
        (PsiMethodCallExpression)factory.createExpressionFromText((qualifier != null ? qualifier + "." : "") + id + "()", null);
      getterCall = (PsiMethodCallExpression)CodeStyleManager.getInstance(myProject).reformat(getterCall);
      if (newExpr.getParent() != null) {
        newExpr = newExpr.replace(getterCall);
      }
      else {
        newExpr = getterCall;
      }
    }
    else {
      // todo: warning
    }
  }

  return newExpr;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:46,代码来源:OldReferenceResolver.java

示例8: 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.generateGetterPrototype方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。