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


Java JVMElementFactory类代码示例

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


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

示例1: getFactory

import com.intellij.psi.JVMElementFactory; //导入依赖的package包/类
@Override
public JVMElementFactory getFactory(Project project) {
  return JavaPsiFacade.getElementFactory(project);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:JavaFactoryProvider.java

示例2: getFactory

import com.intellij.psi.JVMElementFactory; //导入依赖的package包/类
@Override
public JVMElementFactory getFactory(Project project) {
  return GroovyPsiElementFactory.getInstance(project);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:5,代码来源:GroovyFactoryProvider.java

示例3: createSetUpPatternMethod

import com.intellij.psi.JVMElementFactory; //导入依赖的package包/类
public PsiMethod createSetUpPatternMethod(JVMElementFactory factory)
{
	final FileTemplate template = FileTemplateManager.getDefaultInstance().getCodeTemplate(getSetUpMethodFileTemplateDescriptor().getFileName());
	final String templateText = StringUtil.replace(StringUtil.replace(template.getText(), "${BODY}\n", ""), "${NAME}", "setUp");
	return factory.createMethodFromText(templateText, null);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:7,代码来源:JavaTestFramework.java

示例4: createToStringMethod

import com.intellij.psi.JVMElementFactory; //导入依赖的package包/类
/**
 * Creates the <code>toString</code> method.
 *
 * @param selectedMembers the selected members as both {@link com.intellij.psi.PsiField} and {@link com.intellij.psi.PsiMethod}.
 * @param policy          conflict resolution policy
 * @param params          additional parameters stored with key/value in the map.
 * @param template        the template to use
 * @return the created method, null if the method is not created due the user cancels this operation
 * @throws GenerateCodeException       is thrown when there is an error generating the javacode.
 * @throws IncorrectOperationException is thrown by IDEA.
 */
@Nullable
private PsiMethod createToStringMethod(Collection<PsiMember> selectedMembers,
		ConflictResolutionPolicy policy,
		Map<String, String> params,
		TemplateResource template) throws IncorrectOperationException, GenerateCodeException
{
	// generate code using velocity
	String body = GenerationUtil.velocityGenerateCode(clazz, selectedMembers, params, template.getMethodBody(), config.getSortElements(), config.isUseFullyQualifiedName());
	if(logger.isDebugEnabled())
	{
		logger.debug("Method body generated from Velocity:\n" + body);
	}

	// fix weird linebreak problem in IDEA #3296 and later
	body = StringUtil.convertLineSeparators(body);

	// create psi newMethod named toString()
	final JVMElementFactory topLevelFactory = JVMElementFactories.getFactory(clazz.getLanguage(), clazz.getProject());
	if(topLevelFactory == null)
	{
		return null;
	}
	PsiMethod newMethod;
	try
	{
		newMethod = topLevelFactory.createMethodFromText(template.getMethodSignature() + " { " + body + " }", clazz);
		CodeStyleManager.getInstance(clazz.getProject()).reformat(newMethod);
	}
	catch(IncorrectOperationException ignore)
	{
		HintManager.getInstance().showErrorHint(editor, "'toString()' method could not be created from template '" +
				template.getFileName() + '\'');
		return null;
	}

	// insertNewMethod conflict resolution policy (add/replace, duplicate, cancel)
	PsiMethod existingMethod = clazz.findMethodBySignature(newMethod, false);
	PsiMethod toStringMethod = policy.applyMethod(clazz, existingMethod, newMethod, editor);
	if(toStringMethod == null)
	{
		return null; // user cancelled so return null
	}

	if(hasOverrideAnnotation)
	{
		toStringMethod.getModifierList().addAnnotation("java.lang.Override");
	}

	// applyJavaDoc conflict resolution policy (add or keep existing)
	String existingJavaDoc = params.get("existingJavaDoc");
	String newJavaDoc = template.getJavaDoc();
	if(existingJavaDoc != null || newJavaDoc != null)
	{
		// generate javadoc using velocity
		newJavaDoc = GenerationUtil.velocityGenerateCode(clazz, selectedMembers, params, newJavaDoc, config.getSortElements(), config.isUseFullyQualifiedName());
		if(logger.isDebugEnabled())
		{
			logger.debug("JavaDoc body generated from Velocity:\n" + newJavaDoc);
		}

		GenerationUtil.applyJavaDoc(toStringMethod, existingJavaDoc, newJavaDoc);
	}

	// return the created method
	return toStringMethod;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:78,代码来源:GenerateToStringWorker.java


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