use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class SimplifyQuantifierAction method invoke.
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
if (myReplacement == null) {
myQuantifier.delete();
} else {
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
final ASTNode modifier = myQuantifier.getModifier();
final PsiFile f = factory.createFileFromText("dummy.regexp", RegExpFileType.INSTANCE, "a" + myReplacement + (modifier != null ? modifier.getText() : ""));
final RegExpPattern pattern = PsiTreeUtil.getChildOfType(f, RegExpPattern.class);
assert pattern != null;
final RegExpClosure closure = (RegExpClosure) pattern.getBranches()[0].getAtoms()[0];
myQuantifier.replace(closure.getQuantifier());
}
}
use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class CustomAntElementsRegistry method loadContentAsFile.
public static PsiFile loadContentAsFile(Project project, InputStream stream, LanguageFileType fileType) throws IOException {
final StringBuilder builder = new StringBuilder();
try {
int nextByte;
while ((nextByte = stream.read()) >= 0) {
builder.append((char) nextByte);
}
} finally {
stream.close();
}
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
return factory.createFileFromText("_ant_dummy__." + fileType.getDefaultExtension(), fileType, builder, LocalTimeCounter.currentTime(), false, false);
}
use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class GroovyTemplatesFactory method createFromTemplate.
public static PsiFile createFromTemplate(@NotNull final PsiDirectory directory, @NotNull final String name, @NotNull String fileName, @NotNull String templateName, boolean allowReformatting, @NonNls String... parameters) throws IncorrectOperationException {
final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName);
Project project = directory.getProject();
Properties properties = new Properties(FileTemplateManager.getInstance(project).getDefaultProperties());
JavaTemplateUtil.setPackageNameAttribute(properties, directory);
properties.setProperty(NAME_TEMPLATE_PROPERTY, name);
properties.setProperty(LOW_CASE_NAME_TEMPLATE_PROPERTY, StringUtil.decapitalize(name));
for (int i = 0; i < parameters.length; i += 2) {
properties.setProperty(parameters[i], parameters[i + 1]);
}
String text;
try {
text = template.getText(properties);
} catch (Exception e) {
String message = "Unable to load template for " + FileTemplateManager.getInstance(project).internalTemplateToSubject(templateName);
throw new RuntimeException(message, e);
}
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
PsiFile file = factory.createFileFromText(fileName, GroovyFileType.GROOVY_FILE_TYPE, text);
file = (PsiFile) directory.add(file);
if (file != null && allowReformatting && template.isReformatCode()) {
new ReformatCodeProcessor(project, file, null, false).run();
}
return file;
}
use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class RenameUtil method createIdentifierNode.
@NotNull
public static ASTNode createIdentifierNode(PsiManager manager, String name) throws IncorrectOperationException {
if (isKeyword(name)) {
name = "\\" + name;
} else if (!isIdentifier(name)) {
throw new IncorrectOperationException("Illegal identifier: " + name);
}
final PsiFileFactory f = PsiFileFactory.getInstance(manager.getProject());
final RncFile file = (RncFile) f.createFileFromText("dummy.rnc", RncFileType.getInstance(), name + " = bar");
final ASTNode astNode = findFirstGrammarNode(file);
final ASTNode newNode = astNode.findChildByType(RncTokenTypes.IDENTIFIERS);
assert newNode != null;
return newNode;
}
use of com.intellij.psi.PsiFileFactory in project intellij-community by JetBrains.
the class RenameUtil method createLiteralNode.
public static ASTNode createLiteralNode(PsiManager manager, String content) {
final PsiFileFactory f = PsiFileFactory.getInstance(manager.getProject());
final RncFile file = (RncFile) f.createFileFromText("dummy.rnc", RncFileType.getInstance(), "include \"" + content + "\"");
final ASTNode include = findFirstGrammarNode(file);
final ASTNode literal = include.findChildByType(RncTokenTypes.LITERAL);
assert literal != null;
return literal;
}
Aggregations