本文整理汇总了Java中com.intellij.psi.impl.PsiFileFactoryImpl类的典型用法代码示例。如果您正苦于以下问题:Java PsiFileFactoryImpl类的具体用法?Java PsiFileFactoryImpl怎么用?Java PsiFileFactoryImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiFileFactoryImpl类属于com.intellij.psi.impl包,在下文中一共展示了PsiFileFactoryImpl类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleContentChange
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的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);
}
示例2: handleContentChange
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的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);
}
示例3: handleContentChange
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的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);
}
示例4: setName
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的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);
}
示例5: format
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的package包/类
public static String format(final Project project, Language language, String text) {
final PsiFile psiFile = PsiFileFactoryImpl.getInstance(project).createFileFromText("virtual", language, text);
new WriteCommandAction.Simple<String>(project, psiFile) {
@Override
protected void run() throws Throwable {
CodeStyleManager.getInstance(project).reformat(psiFile, false);
}
}.execute();
String formatted = psiFile.getText();
new WriteCommandAction.Simple<String>(project, psiFile) {
@Override
protected void run() throws Throwable {
psiFile.delete();
}
}.execute();
if (formatted == null) {
return text;
}
return formatted;
}
示例6: createLeafFromText
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的package包/类
public static PsiElement createLeafFromText(Project project, Language language, PsiElement context,
String text, IElementType type)
{
PsiFileFactoryImpl factory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project);
PsiElement el = factory.createElementFromText(text, language, type, context);
if ( el==null ) return null;
return PsiTreeUtil.getDeepestFirst(el); // forces parsing of file!!
// start rule depends on root passed in
}
示例7: createFile
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的package包/类
public static PsiFile createFile(Project project, Language language, String text) {
LanguageFileType ftype = language.getAssociatedFileType();
if ( ftype==null ) return null;
String ext = ftype.getDefaultExtension();
String fileName = "___fubar___."+ext; // random name but must have correct extension
PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project);
return factory.createFileFromText(fileName, language, text, false, false);
}
示例8: createLeafFromText
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的package包/类
public static PsiElement createLeafFromText(Project project, PsiElement context,
String text, IElementType type)
{
PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project);
PsiElement el = factory.createElementFromText(text,
ANTLRv4Language.INSTANCE,
type,
context);
return PsiTreeUtil.getDeepestFirst(el); // forces parsing of file!!
// start rule depends on root passed in
}
示例9: createFile
import com.intellij.psi.impl.PsiFileFactoryImpl; //导入依赖的package包/类
public static PsiFile createFile(Project project, String text) {
String fileName = "a.g4"; // random name but must be .g4
PsiFileFactoryImpl factory = (PsiFileFactoryImpl)PsiFileFactory.getInstance(project);
return factory.createFileFromText(fileName, ANTLRv4Language.INSTANCE,
text, false, false);
}