当前位置: 首页>>代码示例>>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;未经允许,请勿转载。