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


Java GenerateMembersUtil类代码示例

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


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


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