本文整理汇总了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);
}
示例2: getFactory
import com.intellij.psi.JVMElementFactory; //导入依赖的package包/类
@Override
public JVMElementFactory getFactory(Project project) {
return GroovyPsiElementFactory.getInstance(project);
}
示例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);
}
示例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;
}