com.intellij.psi.PsiParserFacade Java Examples
The following examples show how to use
com.intellij.psi.PsiParserFacade.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddUsingUtil.java From consulo-csharp with Apache License 2.0 | 6 votes |
@RequiredReadAction private static void addUsingStatementAfter(@Nonnull CSharpUsingListChild afterElement, @Nonnull CSharpUsingNamespaceStatement newStatement) { CSharpUsingListOwner parent = (CSharpUsingListOwner) afterElement.getParent(); if(isUsingListContainsNamespace(parent, newStatement.getReferenceText())) { return; } Project project = afterElement.getProject(); PsiElement whiteSpaceFromText = PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText("\n"); parent.addAfter(whiteSpaceFromText, afterElement); parent.addAfter(newStatement, afterElement.getNode().getTreeNext().getPsi()); }
Example #2
Source File: PantsIntegrationTestCase.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
protected void modify(@NonNls @NotNull String qualifiedName) { final PsiClass psiClass = findClassAndAssert(qualifiedName); final PsiFile psiFile = psiClass.getContainingFile(); final PsiParserFacade parserFacade = PsiParserFacade.SERVICE.getInstance(myProject); final PsiComment comment = parserFacade.createBlockCommentFromText(psiFile.getLanguage(), "Foo"); WriteCommandAction.runWriteCommandAction( myProject, ((Runnable) () -> psiFile.add(comment)) ); FileDocumentManager manager = FileDocumentManager.getInstance(); manager.saveAllDocuments(); }
Example #3
Source File: CSharpModifierListImplUtil.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction public static void addModifier(@Nonnull CSharpModifierList modifierList, @Nonnull DotNetModifier modifier) { PsiElement anchor = modifierList.getLastChild(); CSharpFieldDeclaration field = CSharpFileFactory.createField(modifierList.getProject(), modifier.getPresentableText() + " int b"); PsiElement modifierElement = field.getModifierList().getModifierElement(modifier); PsiElement psiElement = modifierList.addAfter(modifierElement, anchor); modifierList.addAfter(PsiParserFacade.SERVICE.getInstance(modifierList.getProject()).createWhiteSpaceFromText(" "), psiElement); }
Example #4
Source File: CreateGetterSetterQuickfix.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException { ApplicationManager.getApplication().invokeLater( new Runnable() { @Override public void run() { if (classModel.getBodyPsi() == null) return; final StringBuilder builder = new StringBuilder(); GetterSetterMethodBuilder.build(builder, field, generateGetter); new WriteCommandAction.Simple(project) { @Override public void run() { List<HaxeNamedComponent> elements = HaxeElementGenerator.createNamedSubComponentsFromText(project, builder.toString()); PsiElement body = classModel.getBodyPsi(); PsiElement anchor = body.getLastChild(); for (PsiElement element : elements) { PsiElement newLine = createNewLine(); anchor = body.addAfter(element, anchor); anchor = body.addBefore(newLine, anchor); } } private PsiElement createNewLine() { return PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText("\n\n"); } }.execute(); } } ); }
Example #5
Source File: SuppressionUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static PsiComment createComment(@Nonnull Project project, @Nonnull String commentText, @Nonnull Language language) { final PsiParserFacade parserFacade = PsiParserFacade.SERVICE.getInstance(project); return parserFacade.createLineOrBlockCommentFromText(language, commentText); }
Example #6
Source File: AddPantsTargetDependencyFix.java From intellij-pants-plugin with Apache License 2.0 | 4 votes |
public void doInsert( @NotNull PsiFile buildFile, @NotNull final String targetName, @NotNull PantsTargetAddress addressToAdd ) throws IncorrectOperationException { final PyCallExpression targetDefinitionExpression = PantsPsiUtil.findTargets(buildFile).get(targetName); if (targetDefinitionExpression == null) { return; } final Project project = buildFile.getProject(); final PyElementGenerator generator = PyElementGenerator.getInstance(project); final String targetAddressStringToAdd = addressToAdd.toString(); final PyExpression dependenciesArgument = targetDefinitionExpression.getKeywordArgument("dependencies"); if (dependenciesArgument == null) { final PyKeywordArgument keywordArgument = generator.createKeywordArgument(LanguageLevel.forElement(buildFile), "dependencies", "['"+ targetAddressStringToAdd + "']"); Optional.ofNullable(targetDefinitionExpression.getArgumentList()).ifPresent(l -> l.addArgument(keywordArgument)); } else if (dependenciesArgument instanceof PyListLiteralExpression) { PyExpression position = null; // we assume all elements are sorted. for (PyExpression expression : ((PyListLiteralExpression)dependenciesArgument).getElements()) { if (expression instanceof PyStringLiteralExpression && targetAddressStringToAdd.compareTo(((PyStringLiteralExpression)expression).getStringValue()) < 0) { // found a position to insert break; } position = expression; } final PyStringLiteralExpression literalToAdd = generator.createStringLiteralAlreadyEscaped("'" + targetAddressStringToAdd + "'"); if (position != null) { final PsiElement newLine = PsiParserFacade.SERVICE.getInstance(project).createWhiteSpaceFromText("\n"); final PsiElement addedLiteral = dependenciesArgument.addAfter(literalToAdd, position); dependenciesArgument.getNode().addChild(newLine.getNode(), addedLiteral.getNode()); } else { dependenciesArgument.add(literalToAdd); } CodeStyleManager.getInstance(project).reformat(dependenciesArgument); } FileDocumentManager.getInstance().saveAllDocuments(); // dump VFS to FS before refreshing PantsUtil.refreshAllProjects(project); }
Example #7
Source File: CSharpIntroduceHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
protected PsiElement modifyDeclaration(@Nonnull PsiElement declaration) { PsiElement parent = declaration.getParent(); parent.addAfter(PsiParserFacade.SERVICE.getInstance(declaration.getProject()).createWhiteSpaceFromText("\n"), declaration); return declaration; }
Example #8
Source File: HaxeManyStatementsSurrounder.java From intellij-haxe with Apache License 2.0 | 4 votes |
protected static void addStatements(HaxeBlockStatement block, PsiElement[] elements) throws IncorrectOperationException { block.addRangeAfter(elements[0], elements[elements.length - 1], block.getFirstChild()); final PsiElement newLineNode = PsiParserFacade.SERVICE.getInstance(block.getProject()).createWhiteSpaceFromText("\n"); block.addAfter(newLineNode, block.getFirstChild()); }
Example #9
Source File: BaseCreateMethodsFix.java From intellij-haxe with Apache License 2.0 | 4 votes |
protected PsiElement afterAddHandler(PsiElement element, PsiElement anchor) { final PsiElement newLineNode = PsiParserFacade.SERVICE.getInstance(element.getProject()).createWhiteSpaceFromText("\n\n"); anchor.getParent().addBefore(newLineNode, anchor); return anchor; }