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


Java PsiFileFactory.getInstance方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: parseXmlFileInTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@NotNull
private static XmlFile parseXmlFileInTemplate(@NotNull TemplateImpl template, @NotNull CustomTemplateCallback callback,
                                              @NotNull Map<String, String> attributes) {
  XmlTag dummyRootTag = null;
  String templateString = template.getString();
  final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
  if (!containsAttrsVar(template)) {
    XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.html", HTMLLanguage.INSTANCE, templateString, false, true);
    dummyRootTag = dummyFile.getRootTag();
    if (dummyRootTag != null) {
      addMissingAttributes(dummyRootTag, attributes);
    }
  }

  templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
  XmlFile xmlFile =
    (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
  VirtualFile vFile = xmlFile.getVirtualFile();
  if (vFile != null) {
    vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
  }
  return xmlFile;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:TemplateToken.java

示例8: processTags

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
private static void processTags(@NotNull Project project,
                                @Nullable String templateText,
                                @NotNull PairProcessor<XmlTag, Boolean> processor) {
  if (StringUtil.isNotEmpty(templateText)) {
    final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
    XmlFile xmlFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.HTML, templateText);
    XmlTag tag = xmlFile.getRootTag();
    boolean firstTag = true;

    while (tag != null) {
      processor.process(tag, firstTag);
      firstTag = false;
      tag = PsiTreeUtil.getNextSiblingOfType(tag, XmlTag.class);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:EmmetUpdateTagAction.java

示例9: getEnumValues

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@Nullable
public static Set<String> getEnumValues(Project project, @NotNull String regExp) {
  final PsiFileFactory factory = PsiFileFactory.getInstance(project);
  final PsiFile file = factory.createFileFromText("dummy.regexp", RegExpFileType.INSTANCE, regExp);
  final RegExpPattern pattern = (RegExpPattern)file.getFirstChild();
  if (pattern == null) {
    return null;
  }
  final RegExpBranch[] branches = pattern.getBranches();
  final Set<String> values = new HashSet<String>();
  for (RegExpBranch branch : branches) {
    if (analyzeBranch(branch)) {
      values.add(branch.getUnescapedText());
    }
  }
  return values;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:RegExpUtil.java

示例10: parseXmlFileInTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@NotNull
private static XmlFile parseXmlFileInTemplate(TemplateImpl template,
                                              CustomTemplateCallback callback,
                                              List<Pair<String, String>> attributes) {
  XmlTag dummyRootTag = null;
  String templateString = template.getString();
  final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
  if (!containsAttrsVar(template)) {
    XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString);
    dummyRootTag = dummyFile.getRootTag();
    if (dummyRootTag != null) {
      addMissingAttributes(dummyRootTag, attributes);
    }
  }

  templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
  XmlFile xmlFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
  VirtualFile vFile = xmlFile.getVirtualFile();
  if (vFile != null) {
    vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
  }
  return xmlFile;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:TemplateToken.java

示例11: createFromTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
/**
 * Creates new Gitignore file or uses an existing one.
 *
 * @param directory working directory
 * @return file
 *
 * @throws IncorrectOperationException
 */
@Nullable
public PsiFile createFromTemplate(final PsiDirectory directory) throws IncorrectOperationException {
    final String filename = fileType.getIgnoreLanguage().getFilename();
    final PsiFile currentFile = directory.findFile(filename);
    if (currentFile != null) {
        return currentFile;
    }
    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
    final IgnoreLanguage language = fileType.getIgnoreLanguage();

    String content = StringUtil.join(TEMPLATE_NOTE, Constants.NEWLINE);
    if (language.isSyntaxSupported() && !IgnoreBundle.Syntax.GLOB.equals(language.getDefaultSyntax())) {
        content = StringUtil.join(
                content,
                IgnoreBundle.Syntax.GLOB.getPresentation(),
                Constants.NEWLINE,
                Constants.NEWLINE
        );
    }
    final PsiFile file = factory.createFileFromText(filename, fileType, content);
    return (PsiFile) directory.add(file);
}
 
开发者ID:hsz,项目名称:idea-gitignore,代码行数:31,代码来源:IgnoreTemplatesFactory.java

示例12: 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 {
    log.debug("createFromTemplate: dir:" + directory + ", filename: " + fileName);

    final FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate(templateName);

    Properties properties = new Properties(FileTemplateManager.getInstance().getDefaultProperties());

    String text;

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

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

    log.debug("Create file from text");
    final PsiFile file = factory.createFileFromText(fileName, LuaFileType.LUA_FILE_TYPE, text);

    log.debug("Adding file to directory");
    return (PsiFile) directory.add(file);
}
 
开发者ID:consulo,项目名称:consulo-lua,代码行数:27,代码来源:LuaTemplatesFactory.java

示例13: createFromTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
public static PsiElement createFromTemplate(PsiDirectory directory, String fileName, Template template, String text2) {
    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
    if ((new File(fileName)).exists()) {
        throw new RuntimeException("File already exists");
    }
    final PsiFile file = factory.createFileFromText(fileName, GCMLanguageType.INSTANCE, text2);
    return directory.add(file);
}
 
开发者ID:datathings,项目名称:greycat-idea-plugin,代码行数:9,代码来源:GCMTemplatesFactory.java

示例14: NewClassCommandAction

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@Inject
public NewClassCommandAction(@Nonnull Project project,
                             @Nonnull @Assisted("Name") String name,
                             @Nonnull @Assisted("Json") String json,
                             @Nonnull @Assisted PsiDirectory directory,
                             @Nonnull @Assisted JavaConverter converter) {
    super(project);
    this.fileFactory = PsiFileFactory.getInstance(project);
    this.directoryService = JavaDirectoryService.getInstance();
    this.name = Preconditions.checkNotNull(name);
    this.json = Preconditions.checkNotNull(json);
    this.directory = Preconditions.checkNotNull(directory);
    this.converter = Preconditions.checkNotNull(converter);
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:15,代码来源:NewClassCommandAction.java

示例15: setUp

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    final Project project = getProject();
    fileFactory = PsiFileFactory.getInstance(project);
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:8,代码来源:FormatterTest.java


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