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


Java JavaTemplateUtil.setPackageNameAttribute方法代码示例

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


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

示例1: setupCatchBlock

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入方法依赖的package包/类
@Override
public void setupCatchBlock(String exceptionName, PsiElement context, PsiCatchSection catchSection) {
  final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance().getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
  LOG.assertTrue(catchBodyTemplate != null);

  final Properties props = new Properties();
  props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, exceptionName);
  if (context != null && context.isPhysical()) {
    final PsiDirectory directory = context.getContainingFile().getContainingDirectory();
    if (directory != null) {
      JavaTemplateUtil.setPackageNameAttribute(props, directory);
    }
  }

  final PsiCodeBlock codeBlockFromText;
  try {
    codeBlockFromText = PsiElementFactory.SERVICE.getInstance(myProject).createCodeBlockFromText("{\n" + catchBodyTemplate.getText(props) + "\n}", null);
  }
  catch (ProcessCanceledException ce) {
    throw ce;
  }
  catch (Exception e) {
    throw new IncorrectOperationException("Incorrect file template", e);
  }
  catchSection.getCatchBlock().replace(codeBlockFromText);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:JavaPsiImplementationHelperImpl.java

示例2: setupCatchBlock

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入方法依赖的package包/类
@Override
public void setupCatchBlock(@NotNull String exceptionName, @NotNull PsiType exceptionType, PsiElement context, @NotNull PsiCatchSection catchSection) {
  final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance(catchSection.getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
  LOG.assertTrue(catchBodyTemplate != null);

  Properties props = FileTemplateManager.getInstance(myProject).getDefaultProperties();
  props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, exceptionName);
  props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION_TYPE, exceptionType.getCanonicalText());
  if (context != null && context.isPhysical()) {
    final PsiDirectory directory = context.getContainingFile().getContainingDirectory();
    if (directory != null) {
      JavaTemplateUtil.setPackageNameAttribute(props, directory);
    }
  }

  final PsiCodeBlock codeBlockFromText;
  try {
    codeBlockFromText = PsiElementFactory.SERVICE.getInstance(myProject).createCodeBlockFromText("{\n" + catchBodyTemplate.getText(props) + "\n}", null);
  }
  catch (ProcessCanceledException ce) {
    throw ce;
  }
  catch (Exception e) {
    throw new IncorrectOperationException("Incorrect file template", (Throwable)e);
  }
  catchSection.getCatchBlock().replace(codeBlockFromText);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:JavaPsiImplementationHelperImpl.java

示例3: setupCatchBlock

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入方法依赖的package包/类
@Override
public void setupCatchBlock(String exceptionName, PsiElement context, PsiCatchSection catchSection)
{
	final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance(catchSection.getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
	LOG.assertTrue(catchBodyTemplate != null);

	final Properties props = new Properties();
	props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, exceptionName);
	if(context != null && context.isPhysical())
	{
		final PsiDirectory directory = context.getContainingFile().getContainingDirectory();
		if(directory != null)
		{
			JavaTemplateUtil.setPackageNameAttribute(props, directory);
		}
	}

	final PsiCodeBlock codeBlockFromText;
	try
	{
		codeBlockFromText = PsiElementFactory.SERVICE.getInstance(myProject).createCodeBlockFromText("{\n" + catchBodyTemplate.getText(props) + "\n}", null);
	}
	catch(ProcessCanceledException ce)
	{
		throw ce;
	}
	catch(Throwable e)
	{
		throw new IncorrectOperationException("Incorrect file template", e);
	}
	catchSection.getCatchBlock().replace(codeBlockFromText);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:33,代码来源:JavaPsiImplementationHelperImpl.java

示例4: createFromTemplateInternal

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入方法依赖的package包/类
protected static PsiFile createFromTemplateInternal( @NotNull PsiDirectory directory,
                                                     @NotNull String name,
                                                     @NotNull String fileName,
                                                     @NotNull String templateName,
                                                     @NonNls String... parameters )
    throws IncorrectOperationException
{
    // Load template
    FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance();
    FileTemplate template = fileTemplateManager.getJ2eeTemplate( templateName );

    // Process template properties
    Properties properties = new Properties( fileTemplateManager.getDefaultProperties() );
    JavaTemplateUtil.setPackageNameAttribute( properties, directory );
    properties.setProperty( NAME_TEMPLATE_PROPERTY, name );

    // Add parameters
    for( int i = 0; i < parameters.length; i += 2 )
    {
        properties.setProperty( parameters[ i ], parameters[ i + 1 ] );
    }

    // Create text from template with specified properties
    String text;
    try
    {
        text = template.getText( properties );
    }
    catch( Exception e )
    {
        String message = "Unable to load template for " +
                         fileTemplateManager.internalTemplateToSubject( templateName );
        throw new RuntimeException( message, e );
    }

    // Serialized text to file
    PsiManager psiManager = PsiManager.getInstance( directory.getProject() );
    PsiFileFactory fileFactory = PsiFileFactory.getInstance( directory.getProject() );
    PsiFile file = fileFactory.createFileFromText( fileName, text );

    // Reformat the file according to project/default style
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance( psiManager );
    codeStyleManager.reformat( file );

    // Add newly created file to directory
    return (PsiFile) directory.add( file );
}
 
开发者ID:apache,项目名称:polygene-java,代码行数:48,代码来源:AbstractCreateElementActionBase.java


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