本文整理汇总了Java中com.intellij.psi.impl.source.codeStyle.CodeEditUtil类的典型用法代码示例。如果您正苦于以下问题:Java CodeEditUtil类的具体用法?Java CodeEditUtil怎么用?Java CodeEditUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeEditUtil类属于com.intellij.psi.impl.source.codeStyle包,在下文中一共展示了CodeEditUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processText
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
@Override
public void processText(Project project,
Template template,
Document document,
RangeMarker templateRange,
Editor editor) {
if (!template.isToReformat()) return;
PsiDocumentManager.getInstance(project).commitDocument(document);
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
if (!(file instanceof PsiJavaFile)) return;
CharSequence text = document.getImmutableCharSequence();
int prevChar = CharArrayUtil.shiftBackward(text, templateRange.getStartOffset() - 1, " \t");
int nextChar = CharArrayUtil.shiftForward(text, templateRange.getEndOffset(), " \t");
if (prevChar > 0 && text.charAt(prevChar) == '{' && nextChar < text.length() && text.charAt(nextChar) == '}') {
PsiCodeBlock codeBlock = PsiTreeUtil.findElementOfClassAtOffset(file, prevChar, PsiCodeBlock.class, false);
if (codeBlock != null && codeBlock.getTextRange().getStartOffset() == prevChar) {
PsiJavaToken rBrace = codeBlock.getRBrace();
if (rBrace != null && rBrace.getTextRange().getStartOffset() == nextChar) {
CodeEditUtil.markToReformat(rBrace.getNode(), true);
}
}
}
}
示例2: createFileFromText
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
@Override
@NotNull
public PsiFile createFileFromText(@NotNull String name,
@NotNull FileType fileType,
@NotNull CharSequence text,
long modificationStamp,
final boolean eventSystemEnabled,
boolean markAsCopy) {
final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
if(fileType instanceof LanguageFileType){
final Language language =
LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), virtualFile, myManager.getProject());
final PsiFile file = trySetupPsiForFile(virtualFile, language, eventSystemEnabled, markAsCopy);
if (file != null) return file;
}
final SingleRootFileViewProvider singleRootFileViewProvider =
new SingleRootFileViewProvider(myManager, virtualFile, eventSystemEnabled);
final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
if(markAsCopy) CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
return plainTextFile;
}
示例3: postponeFormatting
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
private void postponeFormatting(@NotNull FileViewProvider viewProvider, @NotNull ASTNode child) {
if (!CodeEditUtil.isNodeGenerated(child) && child.getElementType() != TokenType.WHITE_SPACE) {
final int oldIndent = CodeEditUtil.getOldIndentation(child);
LOG.assertTrue(oldIndent >= 0,
"for not generated items old indentation must be defined: element=" + child + ", text=" + child.getText());
}
List<ASTNode> list = getContext().myReformatElements.get(viewProvider);
if (list == null) {
list = new ArrayList<ASTNode>();
getContext().myReformatElements.put(viewProvider, list);
if (Holder.STORE_REFORMAT_ORIGINATOR_STACKTRACE) {
viewProvider.putUserData(REFORMAT_ORIGINATOR, new Throwable());
}
}
list.add(child);
}
示例4: handleReformatMarkers
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
private static void handleReformatMarkers(@NotNull final FileViewProvider key, @NotNull final Set<PostprocessFormattingTask> rangesToProcess) {
final Document document = key.getDocument();
if (document == null) {
return;
}
for (final FileElement fileElement : ((SingleRootFileViewProvider)key).getKnownTreeRoots()) {
fileElement.acceptTree(new RecursiveTreeElementWalkingVisitor() {
@Override
protected void visitNode(TreeElement element) {
if (CodeEditUtil.isMarkedToReformatBefore(element)) {
CodeEditUtil.markToReformatBefore(element, false);
rangesToProcess.add(new ReformatWithHeadingWhitespaceTask(
document.createRangeMarker(element.getStartOffset(), element.getStartOffset()))
);
}
else if (CodeEditUtil.isMarkedToReformat(element)) {
CodeEditUtil.markToReformat(element, false);
rangesToProcess.add(new ReformatWithHeadingWhitespaceTask(
document.createRangeMarker(element.getStartOffset(), element.getStartOffset() + element.getTextLength()))
);
}
super.visitNode(element);
}
});
}
}
示例5: setName
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
@Override
public PsiElement setName(@NotNull final String nameText) throws IncorrectOperationException {
final ASTNode name = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(this);
final String oldName = name.getText();
final PomModel model = PomManager.getModel(getProject());
final XmlAttribute attribute = XmlElementFactory.getInstance(getProject()).createXmlAttribute(nameText, "");
final ASTNode newName = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild((ASTNode)attribute);
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
model.runTransaction(new PomTransactionBase(getParent(), aspect) {
@Override
public PomModelEvent runInner() {
final PomModelEvent event = new PomModelEvent(model);
PsiFile file = getContainingFile();
XmlChangeSet xmlAspectChangeSet = new XmlAspectChangeSetImpl(model, file instanceof XmlFile ? (XmlFile)file : null);
xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), oldName, null));
xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), nameText, getValue()));
event.registerChangeSet(model.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
CodeEditUtil.replaceChild(XmlAttributeImpl.this, name, newName);
return event;
}
});
return this;
}
示例6: testInsertAtOffset
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
public void testInsertAtOffset() throws Exception {
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
String xml = "<root>0123456789</root>";
XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject())
.createFileFromText("foo.xml", StdFileTypes.XML, xml, (long)1, true, false);
//System.out.println(DebugUtil.psiToString(file, false));
XmlTag root = file.getDocument().getRootTag();
final XmlText text1 = root.getValue().getTextElements()[0];
assertFalse(CodeEditUtil.isNodeGenerated(root.getNode()));
final XmlText text = text1;
final XmlElement element = text.insertAtOffset(XmlElementFactory.getInstance(getProject()).createTagFromText("<bar/>"), 5);
assertNotNull(element);
assertTrue(element instanceof XmlText);
assertEquals("01234", element.getText());
assertEquals("<root>01234<bar/>56789</root>", text.getContainingFile().getText());
}
}.execute();
}
示例7: subtreeChanged
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
@Override
public void subtreeChanged() {
super.subtreeChanged();
// We want to reformat method call arguments on method name change because there is a possible situation that they are aligned
// and method change breaks the alignment.
// Example:
// test(1,
// 2);
// Suppose we're renaming the method to test123. We get the following if parameter list is not reformatted:
// test123(1,
// 2);
PsiElement methodCallCandidate = getParent();
if (methodCallCandidate instanceof PsiMethodCallExpression) {
PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)methodCallCandidate;
CodeEditUtil.markToReformat(methodCallExpression.getArgumentList().getNode(), true);
}
}
示例8: replace
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
@Override
public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
PsiElement result = super.replace(newElement);
// We want to reformat method parameters on method name change as well because there is a possible situation that they are aligned
// and method name change breaks the alignment.
// Example:
// public void test(int i,
// int j) {}
// Suppose we're renaming the method to test123. We get the following if parameter list is not reformatted:
// public void test123(int i,
// int j) {}
PsiElement methodCandidate = result.getParent();
if (methodCandidate instanceof PsiMethod) {
PsiMethod method = (PsiMethod)methodCandidate;
CodeEditUtil.markToReformat(method.getParameterList().getNode(), true);
}
return result;
}
示例9: createFileFromText
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
@Override
@NotNull
public PsiFile createFileFromText(@NotNull String name,
@NotNull FileType fileType,
@NotNull CharSequence text,
long modificationStamp,
final boolean physical,
boolean markAsCopy) {
final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
if(fileType instanceof LanguageFileType){
final Language language =
LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), virtualFile, myManager.getProject());
final PsiFile file = trySetupPsiForFile(virtualFile, language, physical, markAsCopy);
if (file != null) return file;
}
final SingleRootFileViewProvider singleRootFileViewProvider =
new SingleRootFileViewProvider(myManager, virtualFile, physical);
final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
if(markAsCopy) CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
return plainTextFile;
}
示例10: handleReformatMarkers
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
private static void handleReformatMarkers(final FileViewProvider key, final TreeSet<PostprocessFormattingTask> rangesToProcess) {
final Document document = key.getDocument();
if (document == null) {
return;
}
for (final FileElement fileElement : ((SingleRootFileViewProvider)key).getKnownTreeRoots()) {
fileElement.acceptTree(new RecursiveTreeElementWalkingVisitor() {
@Override
protected void visitNode(TreeElement element) {
if (CodeEditUtil.isMarkedToReformatBefore(element)) {
CodeEditUtil.markToReformatBefore(element, false);
rangesToProcess.add(new ReformatWithHeadingWhitespaceTask(
document.createRangeMarker(element.getStartOffset(), element.getStartOffset()))
);
}
else if (CodeEditUtil.isMarkedToReformat(element)) {
CodeEditUtil.markToReformat(element, false);
rangesToProcess.add(new ReformatWithHeadingWhitespaceTask(
document.createRangeMarker(element.getStartOffset(), element.getStartOffset() + element.getTextLength()))
);
}
super.visitNode(element);
}
});
}
}
示例11: setName
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
public PsiElement setName(@NotNull final String nameText) throws IncorrectOperationException {
final ASTNode name = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(this);
final String oldName = name.getText();
final PomModel model = PomManager.getModel(getProject());
final XmlAttribute attribute = XmlElementFactory.getInstance(getProject()).createXmlAttribute(nameText, "");
final ASTNode newName = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild((ASTNode)attribute);
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
model.runTransaction(new PomTransactionBase(getParent(), aspect) {
public PomModelEvent runInner() {
final PomModelEvent event = new PomModelEvent(model);
final XmlAspectChangeSetImpl xmlAspectChangeSet = new XmlAspectChangeSetImpl(model, (XmlFile)getContainingFile());
xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), oldName, null));
xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), nameText, getValue()));
event.registerChangeSet(model.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
CodeEditUtil.replaceChild(XmlAttributeImpl.this, name, newName);
return event;
}
});
return this;
}
示例12: testInsertAtOffset
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
public void testInsertAtOffset() throws Exception {
new WriteCommandAction(getProject()) {
@Override
protected void run(final Result result) throws Throwable {
String xml = "<root>0123456789</root>";
XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject())
.createFileFromText("foo.xml", StdFileTypes.XML, xml, (long)1, true, false);
//System.out.println(DebugUtil.psiToString(file, false));
XmlTag root = file.getDocument().getRootTag();
final XmlText text1 = root.getValue().getTextElements()[0];
assertFalse(CodeEditUtil.isNodeGenerated(root.getNode()));
final XmlText text = text1;
final XmlElement element = text.insertAtOffset(XmlElementFactory.getInstance(getProject()).createTagFromText("<bar/>"), 5);
assertNotNull(element);
assertTrue(element instanceof XmlText);
assertEquals("01234", element.getText());
assertEquals("<root>01234<bar/>56789</root>", text.getContainingFile().getText());
}
}.execute();
}
示例13: createFileFromText
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
@Override
@Nonnull
public PsiFile createFileFromText(@Nonnull String name,
@Nonnull FileType fileType,
@Nonnull CharSequence text,
long modificationStamp,
final boolean physical,
boolean markAsCopy) {
final LightVirtualFile virtualFile = new LightVirtualFile(name, fileType, text, modificationStamp);
if (fileType instanceof LanguageFileType) {
final Language language =
LanguageSubstitutors.INSTANCE.substituteLanguage(((LanguageFileType)fileType).getLanguage(), virtualFile, myManager.getProject());
final PsiFile file = trySetupPsiForFile(virtualFile, language, LanguageVersionUtil.findDefaultVersion(language), physical, markAsCopy);
if (file != null) return file;
}
final SingleRootFileViewProvider singleRootFileViewProvider = new SingleRootFileViewProvider(myManager, virtualFile, physical);
final PsiPlainTextFileImpl plainTextFile = new PsiPlainTextFileImpl(singleRootFileViewProvider);
if (markAsCopy) CodeEditUtil.setNodeGenerated(plainTextFile.getNode(), true);
return plainTextFile;
}
示例14: handleReformatMarkers
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
private static void handleReformatMarkers(@Nonnull final FileViewProvider key, @Nonnull final Set<PostprocessFormattingTask> rangesToProcess) {
final Document document = key.getDocument();
if (document == null) {
return;
}
for (final FileElement fileElement : ((AbstractFileViewProvider)key).getKnownTreeRoots()) {
fileElement.acceptTree(new RecursiveTreeElementWalkingVisitor() {
@Override
protected void visitNode(TreeElement element) {
if (CodeEditUtil.isMarkedToReformatBefore(element)) {
CodeEditUtil.markToReformatBefore(element, false);
rangesToProcess.add(new ReformatWithHeadingWhitespaceTask(document.createRangeMarker(element.getStartOffset(), element.getStartOffset())));
}
else if (CodeEditUtil.isMarkedToReformat(element)) {
CodeEditUtil.markToReformat(element, false);
rangesToProcess.add(new ReformatWithHeadingWhitespaceTask(document.createRangeMarker(element.getStartOffset(), element.getStartOffset() + element.getTextLength())));
}
super.visitNode(element);
}
});
}
}
示例15: setName
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil; //导入依赖的package包/类
@Override
public PsiElement setName(@NotNull final String nameText) throws IncorrectOperationException
{
final ASTNode name = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(this);
final String oldName = name.getText();
final PomModel model = PomManager.getModel(getProject());
final XmlAttribute attribute = XmlElementFactory.getInstance(getProject()).createXmlAttribute(nameText, "");
final ASTNode newName = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild((ASTNode) attribute);
final XmlAspect aspect = model.getModelAspect(XmlAspect.class);
model.runTransaction(new PomTransactionBase(getParent(), aspect)
{
@Override
public PomModelEvent runInner()
{
final PomModelEvent event = new PomModelEvent(model);
PsiFile file = getContainingFile();
XmlChangeSet xmlAspectChangeSet = new XmlAspectChangeSetImpl(model, file instanceof XmlFile ? (XmlFile) file : null);
xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), oldName, null));
xmlAspectChangeSet.add(new XmlAttributeSetImpl(getParent(), nameText, getValue()));
event.registerChangeSet(model.getModelAspect(XmlAspect.class), xmlAspectChangeSet);
CodeEditUtil.replaceChild(XmlAttributeImpl.this, name, newName);
return event;
}
});
return this;
}