當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiDirectory.checkCreateFile方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiDirectory.checkCreateFile方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiDirectory.checkCreateFile方法的具體用法?Java PsiDirectory.checkCreateFile怎麽用?Java PsiDirectory.checkCreateFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiDirectory的用法示例。


在下文中一共展示了PsiDirectory.checkCreateFile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doCreate

import com.intellij.psi.PsiDirectory; //導入方法依賴的package包/類
private PsiFile doCreate( PsiDirectory dir, String className, String fqnExtended ) throws IncorrectOperationException
{
  Project project = dir.getProject();

  String fileName = className + ".java";
  VirtualFile srcRoot = ProjectRootManager.getInstance( project ).getFileIndex().getSourceRootForFile( dir.getVirtualFile() );
  dir = getPsiDirectoryForExtensionClass( dir, fqnExtended, srcRoot );

  final PsiPackage pkg = JavaDirectoryService.getInstance().getPackage( dir );
  if( pkg == null )
  {
    throw new IncorrectOperationException( ManBundle.message( "error.new.artifact.nopackage" ) );
  }

  String text =
    "package " + pkg.getQualifiedName() + ";\n" +
    "\n" +
    "import manifold.ext.api.Extension;\n" +
    "import manifold.ext.api.This;\n" +
    "import " + fqnExtended + ";\n" +
    "\n" +
    "@Extension\n" +
    "public class " + className + " {\n" +
    "  public static " + processTypeVars( dir, fqnExtended, StubBuilder::makeTypeVar ) + "void helloWorld(@This " + ClassUtil.extractClassName( fqnExtended ) + processTypeVars( dir, fqnExtended, PsiNamedElement::getName ) + " thiz) {\n" +
    "    System.out.println(\"hello world!\");\n" +
    "  }\n" +
    "}";

  dir.checkCreateFile( fileName );

  final PsiFile file = dir.createFile( fileName );

  try
  {
    new CharSink()
    {
      public Writer openStream() throws IOException
      {
        return new OutputStreamWriter( file.getVirtualFile().getOutputStream( null ) );
      }
    }.write( text );
  }
  catch( IOException e )
  {
    throw new IncorrectOperationException( e.getMessage(), (Throwable)e );
  }

  return file;
}
 
開發者ID:manifold-systems,項目名稱:manifold-ij,代碼行數:50,代碼來源:CreateExtensionMethodsClassAction.java


注:本文中的com.intellij.psi.PsiDirectory.checkCreateFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。