• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java GenerateMembersUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.codeInsight.generation.GenerateMembersUtil的典型用法代码示例。如果您正苦于以下问题:Java GenerateMembersUtil类的具体用法?Java GenerateMembersUtil怎么用?Java GenerateMembersUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GenerateMembersUtil类属于com.intellij.codeInsight.generation包,在下文中一共展示了GenerateMembersUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: appendAccessors

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
private void appendAccessors(final Set<PsiParameter> params, boolean isGetter) {
  final PsiElement element = getElement();
  if (element != null) {
    for (PsiParameter parameter : params) {
      final IntroduceParameterObjectProcessor.ParameterChunk parameterChunk =
        IntroduceParameterObjectProcessor.ParameterChunk.getChunkByParameter(parameter, parameters);
      LOGGER.assertTrue(parameterChunk != null);
      final PsiField field = parameterChunk.getField();
      if (field != null) {
        element.add(isGetter
                    ? GenerateMembersUtil.generateGetterPrototype(field)
                    : GenerateMembersUtil.generateSetterPrototype(field));
      }

    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AppendAccessorsUsageInfo.java


示例2: processUsagesForMethod

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
private void processUsagesForMethod(final boolean deleteMethodHierarchy, PsiMethod method, int[] paramPermutation, String getterName, PsiMethod delegatedMethod,
                                      List<FixableUsageInfo> usages) {
  for (PsiReference reference : ReferencesSearch.search(method)) {
    final PsiElement referenceElement = reference.getElement();
    final PsiMethodCallExpression call = (PsiMethodCallExpression)referenceElement.getParent();
    final String access;
    if (call.getMethodExpression().getQualifierExpression() == null) {
      access = field.getName();
    } else {
      access = getterName + "()";
      if (getter == null) {
        getter = GenerateMembersUtil.generateGetterPrototype(field);
      }
    }
    usages.add(new InlineDelegatingCall(call, paramPermutation, access, delegatedMethod.getName()));
  }
  if (deleteMethodHierarchy) {
    usages.add(new DeleteMethod(method));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:RemoveMiddlemanProcessor.java


示例3: anyFieldsWithGettersPresent

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的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 = GenerateMembersUtil.generateGetterPrototype(psiField);

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

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

  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:Util.java


示例4: testSetupGeneratedMethodNotOverridingInitialBody

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
public void testSetupGeneratedMethodNotOverridingInitialBody() throws Exception {
  String methodText = "public void tearDown() {\n //comment\n }";
  PsiElementFactory factory = JavaPsiFacade.getElementFactory(getProject());
  PsiMethod method = factory.createMethodFromText(methodText, null);
  GenerateMembersUtil.setupGeneratedMethod(method);
  assertEquals(methodText, method.getText());
  
  //empty template
  PsiJavaFile file = (PsiJavaFile)PsiFileFactory.getInstance(getProject())
    .createFileFromText(JavaLanguage.INSTANCE, "class A {void foo() {}}\n class B extends A {void foo() {}\n}");

  method = file.getClasses()[1].getMethods()[0];
  GenerateMembersUtil.setupGeneratedMethod(method);
  assertEquals("@Override void foo() {\n" +
               "    super.foo();\n" +
               "    }", method.getText());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GenerateMembersUtilTest.java


示例5: findInsertionAnchor

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
@Override
public PsiElement findInsertionAnchor(@NotNull PsiClass aClass, @NotNull PsiElement leaf) {
  PsiElement parent = aClass instanceof GroovyScriptClass ? aClass.getContainingFile() : ((GrTypeDefinition)aClass).getBody();
  if (parent == null) return null;

  if (!PsiTreeUtil.isAncestor(parent, leaf, true)) {
    return null; // we are not in class body
  }

  PsiElement element = PsiTreeUtil.findPrevParent(parent, leaf);

  PsiElement lBrace = aClass.getLBrace();
  if (lBrace == null) {
    return null;
  }
  else {
    PsiElement rBrace = aClass.getRBrace();
    if (!GenerateMembersUtil.isChildInRange(element, lBrace.getNextSibling(), rBrace)) {
      return null;
    }
  }

  return element;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GroovyGenerationInfo.java


示例6: generateMethodPrototype

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
public static GrMethod generateMethodPrototype(GrTypeDefinition aClass,
                                               PsiMethod method,
                                               PsiSubstitutor substitutor) {
  final Project project = aClass.getProject();
  final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);

  String templName = isAbstract ? JavaTemplateUtil.TEMPLATE_IMPLEMENTED_METHOD_BODY : JavaTemplateUtil.TEMPLATE_OVERRIDDEN_METHOD_BODY;
  final FileTemplate template = FileTemplateManager.getInstance(method.getProject()).getCodeTemplate(templName);
  final GrMethod result = (GrMethod)GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass);

  setupModifierList(result);
  setupOverridingMethodBody(project, method, result, template, substitutor);
  setupReturnType(result, method);

  setupAnnotations(aClass, method, result);

  GroovyChangeContextUtil.encodeContextInfo(result);
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GroovyOverrideImplementUtil.java


示例7: generateGetters

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的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


示例8: generateSetters

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
@Override
public PsiMethod[] generateSetters(PsiField field) {
  final PsiMethod setter = GenerateMembersUtil.generateSimpleSetterPrototype(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:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:JavaFxGetterSetterPrototypeProvider.java


示例9: addGetterSetterElements

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
private static void addGetterSetterElements(CompletionResultSet result, PsiClass parent) {
  List<PsiMethod> prototypes = ContainerUtil.newArrayList();
  for (PsiField field : parent.getFields()) {
    if (!(field instanceof PsiEnumConstant)) {
      prototypes.add(GenerateMembersUtil.generateGetterPrototype(field));
      prototypes.add(GenerateMembersUtil.generateSetterPrototype(field));
    }
  }
  for (final PsiMethod prototype : prototypes) {
    if (parent.findMethodBySignature(prototype, false) == null) {
      Icon icon = prototype.getIcon(Iconable.ICON_FLAG_VISIBILITY);
      result.addElement(createGenerateMethodElement(prototype, PsiSubstitutor.EMPTY, icon, "", new InsertHandler<LookupElement>() {
        @Override
        public void handleInsert(InsertionContext context, LookupElement item) {
          removeLookupString(context);

          insertGenerationInfos(context, Arrays.asList(new PsiGenerationInfo<PsiMethod>(prototype)));
        }
      }));
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:JavaGenerateMemberCompletionContributor.java


示例10: invoke

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project,
                   @NotNull PsiFile file,
                   @Nullable("is null when called from inspection") Editor editor,
                   @NotNull PsiElement startElement,
                   @NotNull PsiElement endElement) {
  final PsiClass myClass = (PsiClass)startElement;
  if (!FileModificationService.getInstance().prepareFileForWrite(myClass.getContainingFile())) return;
  PsiCodeBlock body;
  if (myClass.isInterface() && (body = myMethodPrototype.getBody()) != null) body.delete();
  for (String exception : myExceptions) {
    PsiUtil.addException(myMethodPrototype, exception);
  }
  PsiMethod method = (PsiMethod)myClass.add(myMethodPrototype);
  method = (PsiMethod)method.replace(reformat(project, method));
  if (editor != null && method.getContainingFile() == file) {
    GenerateMembersUtil.positionCaret(editor, method, true);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:AddMethodFix.java


示例11: registerQuickFix

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的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


示例12: generateMethodPrototype

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
public static GrMethod generateMethodPrototype(GrTypeDefinition aClass,
                                               PsiMethod method,
                                               PsiSubstitutor substitutor) {
  final Project project = aClass.getProject();
  final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);

  String templName = isAbstract ? JavaTemplateUtil.TEMPLATE_IMPLEMENTED_METHOD_BODY : JavaTemplateUtil.TEMPLATE_OVERRIDDEN_METHOD_BODY;
  final FileTemplate template = FileTemplateManager.getInstance().getCodeTemplate(templName);
  final GrMethod result = (GrMethod)GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass);

  setupModifierList(result);
  setupOverridingMethodBody(project, method, result, template, substitutor);
  setupReturnType(result, method);

  setupAnnotations(aClass, method, result);

  GroovyChangeContextUtil.encodeContextInfo(result);
  return result;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:GroovyOverrideImplementUtil.java


示例13: insertGenerationInfos

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
private static void insertGenerationInfos(InsertionContext context, List<PsiGenerationInfo<PsiMethod>> infos)
{
	List<PsiGenerationInfo<PsiMethod>> newInfos = GenerateMembersUtil.insertMembersAtOffset(context.getFile(), context.getStartOffset(), infos);
	if(!newInfos.isEmpty())
	{
		final List<PsiElement> elements = new ArrayList<PsiElement>();
		for(GenerationInfo member : newInfos)
		{
			if(!(member instanceof TemplateGenerationInfo))
			{
				final PsiMember psiMember = member.getPsiMember();
				if(psiMember != null)
				{
					elements.add(psiMember);
				}
			}
		}

		GlobalInspectionContextBase.cleanupElements(context.getProject(), null, elements.toArray(new PsiElement[elements.size()]));
		newInfos.get(0).positionCaret(context.getEditor(), true);
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:JavaGenerateMemberCompletionContributor.java


示例14: processUsagesForMethod

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
private void processUsagesForMethod(final boolean deleteMethodHierarchy, PsiMethod method, int[] paramPermutation, String getterName, PsiMethod delegatedMethod,
                                    List<FixableUsageInfo> usages) {
  for (PsiReference reference : ReferencesSearch.search(method)) {
    final PsiElement referenceElement = reference.getElement();
    final PsiMethodCallExpression call = (PsiMethodCallExpression)referenceElement.getParent();
    final String access;
    if (call.getMethodExpression().getQualifierExpression() == null) {
      access = field.getName();
    } else {
      access = getterName + "()";
      if (getter == null) {
        getter = GenerateMembersUtil.generateGetterPrototype(field);
      }
    }
    usages.add(new InlineDelegatingCall(call, paramPermutation, access, delegatedMethod.getName()));
  }
  if (deleteMethodHierarchy) {
    usages.add(new DeleteMethod(method));
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:RemoveMiddlemanProcessor.java


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


示例16: getPropertiesHandlersNames

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的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


示例17: postAddAction

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
protected void postAddAction(@NotNull PsiFile file,
                             @Nullable("is null when called from inspection") Editor editor,
                             PsiMethod newMethod) {
  if (editor != null && newMethod.getContainingFile() == file) {
    GenerateMembersUtil.positionCaret(editor, newMethod, true);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:AddMethodFix.java


示例18: beforeTemplateFinished

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
@Override
protected void beforeTemplateFinished(PsiClass aClass, PsiField field) {
  PsiMethod getterPrototype = GenerateMembersUtil.generateSimpleGetterPrototype(field);
  if (aClass.findMethodsBySignature(getterPrototype, false).length == 0) {
    aClass.add(getterPrototype);
  }


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


示例19: addOrReplaceMethod

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
private static void addOrReplaceMethod(final PsiMethod method, final PsiClass implementor) throws IncorrectOperationException {
  final PsiMethod accept = implementor.findMethodBySignature(method, false);
  if (accept != null) {
    accept.replace(method);
  }
  else {
    GenerateMembersUtil.insertMembersAtOffset(implementor.getContainingFile(), implementor.getLastChild().getTextOffset(), Collections.<GenerationInfo>singletonList(new PsiGenerationInfo<PsiMethod>(method)));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:GenerateVisitorByHierarchyAction.java


示例20: generateDummyMethod

import com.intellij.codeInsight.generation.GenerateMembersUtil; //导入依赖的package包/类
@Nullable
private static PsiMethod generateDummyMethod(Editor editor, PsiFile file) throws IncorrectOperationException {
  final PsiMethod method = TestIntegrationUtils.createDummyMethod(file);
  final PsiGenerationInfo<PsiMethod> info = OverrideImplementUtil.createGenerationInfo(method);

  int offset = findOffsetToInsertMethodTo(editor, file);
  GenerateMembersUtil.insertMembersAtOffset(file, offset, Collections.singletonList(info));

  final PsiMethod member = info.getPsiMember();
  return member != null ? CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(member) : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:BaseGenerateTestSupportMethodAction.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InnerClasses类代码示例发布时间:2022-05-22
下一篇:
Java ConnectionConfig类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap