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


Java PsiFileFactory類代碼示例

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


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

示例1: actionPerformed

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
@Override
public void actionPerformed(AnActionEvent anActionEvent)
{
    final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(anActionEvent.getDataContext());
    final Project project = anActionEvent.getProject();

    Xsd2Raml xsd2Raml = new Xsd2Raml(file.getUrl());
    String raml = xsd2Raml.getRaml();

    PsiFile psiFile = PsiFileFactory.getInstance(anActionEvent.getProject()).createFileFromText(RamlLanguage.INSTANCE, raml);

    new WriteCommandAction.Simple(project, psiFile) {
        @Override
        protected void run() throws Throwable {
            psiFile.setName(file.getNameWithoutExtension() + "." + RamlFileType.INSTANCE.getDefaultExtension());

            PsiDirectory directory = CommonDataKeys.PSI_FILE.getData(anActionEvent.getDataContext()).getContainingDirectory();
            directory.add(psiFile);
        }
    }.execute();

}
 
開發者ID:machaval,項目名稱:mule-intellij-plugins,代碼行數:23,代碼來源:XSDToRAMLAction.java

示例2: createFromTemplate

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
public static PsiFile createFromTemplate(final PsiDirectory directory, final String name,
                                         String fileName, String templateName,
                                         @NonNls String... parameters) throws IncorrectOperationException {

    final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName);
    String text;

    try {
        text = template.getText();
    } catch (Exception e) {
        throw new RuntimeException("Unable to load template for " +
                FileTemplateManager.getInstance().internalTemplateToSubject(templateName), e);
    }

    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());

    final PsiFile file = factory.createFileFromText(fileName, WeexFileType.INSTANCE, text);
    CodeStyleManager.getInstance(directory.getProject()).reformat(file);
    return (PsiFile) directory.add(file);
}
 
開發者ID:misakuo,項目名稱:weex-language-support,代碼行數:21,代碼來源:WeexTemplateFactory.java

示例3: suggestKeywords

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
private static Collection<String> suggestKeywords(PsiElement position) {
    TextRange posRange = position.getTextRange();
    CupFile posFile = (CupFile) position.getContainingFile();
    TextRange range = new TextRange(0, posRange.getStartOffset());
    String text = range.isEmpty() ? CompletionInitializationContext.DUMMY_IDENTIFIER : range.substring(posFile.getText());
    int completionOffset = posRange.getStartOffset() - range.getStartOffset(); // = posRange.getStartOffset() ...

    PsiFile file = PsiFileFactory.getInstance(posFile.getProject()).createFileFromText("a.cup", CupLanguage.INSTANCE, text, true, false);
    GeneratedParserUtilBase.CompletionState state = new GeneratedParserUtilBase.CompletionState(completionOffset) {
        @Nullable
        @Override
        public String convertItem(Object o) {
            if (o == CupTypes.IDENTIFIER) {
                return null;
            }
            return o.toString();
        }
    };
    file.putUserData(GeneratedParserUtilBase.COMPLETION_STATE_KEY, state);
    TreeUtil.ensureParsed(file.getNode());

    return state.items;
}
 
開發者ID:Tirke,項目名稱:cup-plugin,代碼行數:24,代碼來源:CupCompletionContributor.java

示例4: doRun

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
@Override
    public void doRun() {
        PsiDirectory psiParent = PsiHelper.findPsiDirByPath(project, file.getParentFile().getPath());
        if(psiParent==null){
            ReportHelper.setState(ExecutionState.FAILED);
            return;
        }

        try {
            PsiFile psiResultFile = PsiFileFactory.getInstance(project).createFileFromText(file.getName(), PlainTextFileType.INSTANCE, content);
//            PsiFile psiFile = psiDirectory.createFile(psiDirectory.createFile(file.getName()).getName());
//            psiFile.getVirtualFile().
            psiParent.add(psiResultFile);
        } catch (IncorrectOperationException ex){
            Logger.log("CreateFileAction " + ex.getMessage());
            Logger.printStack(ex);
            ReportHelper.setState(ExecutionState.FAILED);
            return;
        }
    }
 
開發者ID:CeH9,項目名稱:PackageTemplates,代碼行數:21,代碼來源:CreateFileAction.java

示例5: handleContentChange

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
@Override
public FileReferenceNode handleContentChange(@NotNull FileReferenceNode fileReferenceNode,
        @NotNull TextRange range, String newContent) throws IncorrectOperationException {
    String oldText = fileReferenceNode.getText();
    String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText
            .substring(range.getEndOffset());
    Project project = fileReferenceNode.getProject();
    PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
    IElementType type = ProtoParserDefinition.rule(ProtoParser.RULE_fileReference);
    ScopeNode context = fileReferenceNode.getContext();
    PsiElement newNode = factory
            .createElementFromText(newText, ProtoLanguage.INSTANCE, type, context);
    if (newNode == null) {
        throw new IncorrectOperationException();
    }
    return (FileReferenceNode) fileReferenceNode.replace(newNode);
}
 
開發者ID:protostuff,項目名稱:protobuf-jetbrains-plugin,代碼行數:18,代碼來源:FileReferenceNodeManipulator.java

示例6: handleContentChange

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
@Override
public FieldReferenceNode handleContentChange(@NotNull FieldReferenceNode node,
        @NotNull TextRange range, String newContent) throws IncorrectOperationException {
    String oldText = node.getText();
    String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText
            .substring(range.getEndOffset());
    Project project = node.getProject();
    PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
    IElementType type = ProtoParserDefinition.rule(ProtoParser.RULE_fieldRerefence);
    ScopeNode context = node.getContext();
    PsiElement newNode = factory
            .createElementFromText(newText, ProtoLanguage.INSTANCE, type, context);
    if (newNode == null) {
        throw new IncorrectOperationException();
    }
    return (FieldReferenceNode) node.replace(newNode);
}
 
開發者ID:protostuff,項目名稱:protobuf-jetbrains-plugin,代碼行數:18,代碼來源:FieldReferenceNodeManipulator.java

示例7: handleContentChange

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
@Override
public TypeReferenceNode handleContentChange(@NotNull TypeReferenceNode node,
        @NotNull TextRange range, String newContent) throws IncorrectOperationException {
    String oldText = node.getText();
    String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText
            .substring(range.getEndOffset());
    Project project = node.getProject();
    PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
    IElementType type = ProtoParserDefinition.rule(ProtoParser.RULE_typeReference);
    ScopeNode context = node.getContext();
    PsiElement newNode = factory
            .createElementFromText(newText, ProtoLanguage.INSTANCE, type, context);
    if (newNode == null) {
        throw new IncorrectOperationException();
    }
    return (TypeReferenceNode) node.replace(newNode);
}
 
開發者ID:protostuff,項目名稱:protobuf-jetbrains-plugin,代碼行數:18,代碼來源:TypeReferenceNodeManipulator.java

示例8: setName

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
/**
 * Set name.
 */
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
    ASTNode node = getNode();
    IElementType elementType = node.getElementType();
    if (elementType instanceof RuleIElementType) {
        RuleIElementType ruleElementType = (RuleIElementType) elementType;
        int ruleIndex = ruleElementType.getRuleIndex();
        Project project = getProject();
        PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
        IElementType type = ProtoParserDefinition.rule(ruleIndex);
        ScopeNode context = getContext();
        PsiElement newNode = factory.createElementFromText(name, ProtoLanguage.INSTANCE, type, context);
        if (newNode == null) {
            throw new IncorrectOperationException();
        }
        return replace(newNode);
    }
    throw new IncorrectOperationException(OPERATION_NOT_SUPPORTED);
}
 
開發者ID:protostuff,項目名稱:protobuf-jetbrains-plugin,代碼行數:22,代碼來源:GenericNameNode.java

示例9: createFromTemplate

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
public static PsiFile createFromTemplate(PsiDirectory directory, String fileName, String templateName) throws IncorrectOperationException {
	final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName);

	Project project = directory.getProject();

	String text;
	try {
		text = template.getText();
	} catch (Exception e) {
		throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance(project).internalTemplateToSubject(templateName), e);
	}

	final PsiFileFactory factory = PsiFileFactory.getInstance(project);
	PsiFile file = factory.createFileFromText(fileName, NullShaderFileType.INSTANCE, text);

	file = (PsiFile) directory.add(file);

	return file;
}
 
開發者ID:warlockcodes,項目名稱:Null-Engine,代碼行數:20,代碼來源:NullShaderTemplatesFactory.java

示例10: doTextTest

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
protected void doTextTest(final String text, final String textAfter, @NotNull CheckPolicy checkPolicy)
  throws IncorrectOperationException {
  final String fileName = "before." + getFileExtension();
  final PsiFile file = createFileFromText(text, fileName, PsiFileFactory.getInstance(getProject()));

  if (checkPolicy.isCheckDocument()) {
    checkDocument(file, text, textAfter);
  }

  if (checkPolicy.isCheckPsi()) {
    /*
    restoreFileContent(file, text);

    checkPsi(file, textAfter);
    */
  }


}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:FormatterTestCase.java

示例11: testNonPhysicalFile

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
public void testNonPhysicalFile() throws Exception {
  String fileName = "Test.java";
  FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFileName(fileName);
  PsiFile psiFile = PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, fileType, "class Test {}", 0, false);
  VirtualFile virtualFile = psiFile.getViewProvider().getVirtualFile();
  Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
  assertNotNull(document);
  EditorFactory editorFactory = EditorFactory.getInstance();
  Editor editor = editorFactory.createViewer(document, getProject());
  try {
    editor.getSelectionModel().setSelection(0, document.getTextLength());
    String syntaxInfo = getSyntaxInfo(editor, psiFile);
    assertEquals("foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=class \n" +
                 "foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=Test {}\n", syntaxInfo);
  }
  finally {
    editorFactory.releaseEditor(editor);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:SyntaxInfoConstructionTest.java

示例12: parseText

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
private PsiElement parseText(String text) {
  final Object source = getSource();
  try {
    if (source instanceof PsiViewerExtension) {
      return ((PsiViewerExtension)source).createElement(myProject, text);
    }
    if (source instanceof FileType) {
      final FileType type = (FileType)source;
      String ext = type.getDefaultExtension();
      if (myExtensionComboBox.isVisible()) {
        ext = myExtensionComboBox.getSelectedItem().toString().toLowerCase();
      }
      if (type instanceof LanguageFileType) {
        final Language dialect = (Language)myDialectComboBox.getSelectedItem();
        if (dialect != null) {
          return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, dialect, text);
        }
      }
      return PsiFileFactory.getInstance(myProject).createFileFromText("Dummy." + ext, type, text);
    }
  }
  catch (IncorrectOperationException e) {
    Messages.showMessageDialog(myProject, e.getMessage(), "Error", Messages.getErrorIcon());
  }
  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:27,代碼來源:PsiViewerDialog.java

示例13: updateFileTypeForEditorComponent

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
private void updateFileTypeForEditorComponent(@NotNull ComboBox inputComboBox) {
  final Component editorComponent = inputComboBox.getEditor().getEditorComponent();

  if (editorComponent instanceof EditorTextField) {
    boolean isRegexp = myCbRegularExpressions.isSelectedWhenSelectable();
    FileType fileType = PlainTextFileType.INSTANCE;
    if (isRegexp) {
      Language regexpLanguage = Language.findLanguageByID("RegExp");
      if (regexpLanguage != null) {
        LanguageFileType regexpFileType = regexpLanguage.getAssociatedFileType();
        if (regexpFileType != null) {
          fileType = regexpFileType;
        }
      }
    }
    String fileName = isRegexp ? "a.regexp" : "a.txt";
    final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(fileName, fileType, ((EditorTextField)editorComponent).getText(), -1, true);

    ((EditorTextField)editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file));
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:22,代碼來源:FindDialog.java

示例14: createFromTemplate

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
@NotNull
@Override
public PsiElement createFromTemplate(final Project project, final PsiDirectory directory, String fileName, final FileTemplate template,
                                     final String templateText,
                                     @NotNull final Map<String, Object> props) throws IncorrectOperationException {
  fileName = checkAppendExtension(fileName, template);

  if (FileTypeManager.getInstance().isFileIgnored(fileName)) {
    throw new IncorrectOperationException("This filename is ignored (Settings | Editor | File Types | Ignore files and folders)");
  }

  directory.checkCreateFile(fileName);
  FileType type = FileTypeRegistry.getInstance().getFileTypeByFileName(fileName);
  PsiFile file = PsiFileFactory.getInstance(project).createFileFromText(fileName, type, templateText);

  if (template.isReformatCode()) {
    CodeStyleManager.getInstance(project).reformat(file);
  }

  file = (PsiFile)directory.add(file);
  return file;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:23,代碼來源:DefaultCreateFromTemplateHandler.java

示例15: getConfigPsiFile

import com.intellij.psi.PsiFileFactory; //導入依賴的package包/類
@Nullable
public BuildoutCfgFile getConfigPsiFile() {
  File cfg = getConfigFile();
  if (cfg != null && cfg.exists()) {
    try {
      // this method is called before the project initialization is complete, so it has to use createFileFromText() instead
      // of PsiManager.findFile()
      String text = FileUtil.loadFile(cfg);
      final PsiFile configFile = PsiFileFactory
        .getInstance(getModule().getProject()).createFileFromText("buildout.cfg",
                                                                  BuildoutCfgLanguage.INSTANCE, text);
      if (configFile != null && configFile instanceof BuildoutCfgFile) {
        return (BuildoutCfgFile)configFile;
      }
    }
    catch (Exception ignored) {
    }
  }
  return null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:21,代碼來源:BuildoutFacet.java


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