本文整理汇总了Java中com.intellij.psi.impl.CheckUtil.checkWritable方法的典型用法代码示例。如果您正苦于以下问题:Java CheckUtil.checkWritable方法的具体用法?Java CheckUtil.checkWritable怎么用?Java CheckUtil.checkWritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.impl.CheckUtil
的用法示例。
在下文中一共展示了CheckUtil.checkWritable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: replace
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
public PsiElement replace( PsiElement newElement ) throws IncorrectOperationException
{
// just add new element to the containing class
final PsiClass containingClass = getContainingClass();
if( null != containingClass )
{
CheckUtil.checkWritable( containingClass );
return containingClass.add( newElement );
}
return null;
}
示例2: reformat
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
@NotNull
public PsiElement reformat(@NotNull PsiElement element, boolean canChangeWhiteSpacesOnly) throws IncorrectOperationException {
CheckUtil.checkWritable(element);
if( !SourceTreeToPsiMap.hasTreeElement( element ) )
{
return element;
}
ASTNode treeElement = SourceTreeToPsiMap.psiElementToTree(element);
final PsiElement formatted = SourceTreeToPsiMap.treeElementToPsi(new CodeFormatterFacade(getSettings(), element.getLanguage()).processElement(treeElement));
if (!canChangeWhiteSpacesOnly) {
return postProcessElement(formatted);
}
return formatted;
}
示例3: delete
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
public void delete() throws IncorrectOperationException {
PsiElement parent = getParent();
if (parent instanceof ASTDelegatePsiElement) {
CheckUtil.checkWritable(this);
((ASTDelegatePsiElement)parent).deleteChildInternal(getNode());
}
else if (parent instanceof CompositeElement) {
CheckUtil.checkWritable(this);
((CompositeElement)parent).deleteChildInternal(getNode());
}
else if (parent instanceof PsiFile) {
CheckUtil.checkWritable(this);
parent.deleteChildRange(this, this);
}
else {
throw new UnsupportedOperationException(getClass().getName() + " under " + (parent == null ? "null" : parent.getClass().getName()));
}
}
示例4: formatInternal
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
private void formatInternal(Formatter formatter, PsiFile file, List<Range<Integer>> ranges)
throws IncorrectOperationException {
ApplicationManager.getApplication().assertWriteAccessAllowed();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
CheckUtil.checkWritable(file);
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
if (document != null) {
try {
List<Replacement> replacements =
formatter
.getFormatReplacements(document.getText(), ranges)
.stream()
.sorted(
comparing((Replacement r) -> r.getReplaceRange().lowerEndpoint()).reversed())
.collect(Collectors.toList());
performReplacements(document, replacements);
} catch (FormatterException e) {
// Do not format on errors
}
}
}
示例5: reformatRangeImpl
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
private PsiElement reformatRangeImpl(final PsiElement element,
final int startOffset,
final int endOffset,
boolean canChangeWhiteSpacesOnly) throws IncorrectOperationException {
LOG.assertTrue(element.isValid());
CheckUtil.checkWritable(element);
if( !SourceTreeToPsiMap.hasTreeElement( element ) )
{
return element;
}
ASTNode treeElement = SourceTreeToPsiMap.psiElementToTree(element);
final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(getSettings());
final PsiElement formatted = SourceTreeToPsiMap.treeElementToPsi(codeFormatter.processRange(treeElement, startOffset, endOffset));
return canChangeWhiteSpacesOnly ? formatted : postProcessElement(formatted);
}
示例6: updateText
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
public PsiLanguageInjectionHost updateText(@NotNull String text) {
try {
final String quoteChar = getTextLength() > 0 ? getText().substring(0, 1) : "";
String contents = StringUtil.containsAnyChar(quoteChar, "'\"") ?
StringUtil.trimEnd(StringUtil.trimStart(text, quoteChar), quoteChar) : text;
XmlAttribute newAttribute = XmlElementFactory.getInstance(getProject()).createXmlAttribute("q", contents);
XmlAttributeValue newValue = newAttribute.getValueElement();
CheckUtil.checkWritable(this);
replaceAllChildrenToChildrenOf(newValue.getNode());
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
return this;
}
示例7: reformat
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
@NotNull
public PsiElement reformat(@NotNull PsiElement element, boolean canChangeWhiteSpacesOnly) throws IncorrectOperationException {
CheckUtil.checkWritable(element);
if( !SourceTreeToPsiMap.hasTreeElement( element ) )
{
return element;
}
ASTNode treeElement = SourceTreeToPsiMap.psiElementToTree(element);
final PsiElement formatted = SourceTreeToPsiMap.treeElementToPsi(new CodeFormatterFacade(getSettings()).processElement(treeElement));
if (!canChangeWhiteSpacesOnly) {
return postProcessElement(formatted);
}
return formatted;
}
示例8: delete
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
public void delete() throws IncorrectOperationException {
PsiElement parent = getParent();
if (parent instanceof ASTDelegatePsiElement) {
CheckUtil.checkWritable(this);
((ASTDelegatePsiElement)parent).deleteChildInternal(getNode());
}
else if (parent instanceof CompositePsiElement) {
CheckUtil.checkWritable(this);
((CompositePsiElement)parent).deleteChildInternal(getNode());
}
else if (parent instanceof PsiFile) {
CheckUtil.checkWritable(this);
parent.deleteChildRange(this, this);
}
else {
throw new UnsupportedOperationException(getClass().getName() + " under " + (parent == null ? "null" : parent.getClass().getName()));
}
}
示例9: delete
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
public static void delete(@NotNull FrogAttribute attribute) throws IncorrectOperationException {
// see ASTDelegatePsiElement.delete
PsiElement parent = attribute.getParent();
if (parent instanceof ASTDelegatePsiElement) {
CheckUtil.checkWritable(attribute);
ASTNode node = attribute.getNode();
ASTNode nextNode = node.getTreeNext();
((ASTDelegatePsiElement) parent).deleteChildInternal(node);
if (nextNode != null && nextNode.getElementType() == FrogTypes.FROG_SEMICOLON) {
parent.getNode().removeChild(nextNode);
}
} else {
throw new UnsupportedOperationException(attribute.getClass().getName() + " under " + (parent == null ? "null" : parent.getClass().getName()));
}
}
示例10: deleteChildRange
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
public void deleteChildRange(PsiElement first, PsiElement last) throws IncorrectOperationException
{
CheckUtil.checkWritable(this);
if(first == null)
{
LOG.assertTrue(last == null);
return;
}
ASTNode firstElement = SourceTreeToPsiMap.psiElementToTree(first);
ASTNode lastElement = SourceTreeToPsiMap.psiElementToTree(last);
CompositeElement treeElement = calcTreeElement();
LOG.assertTrue(firstElement.getTreeParent() == treeElement);
LOG.assertTrue(lastElement.getTreeParent() == treeElement);
CodeEditUtil.removeChildren(treeElement, firstElement, lastElement);
}
示例11: replace
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
LOG.assertTrue(getTreeParent() != null);
CheckUtil.checkWritable(this);
TreeElement elementCopy = ChangeUtil.copyToElement(newElement);
getTreeParent().replaceChildInternal(this, elementCopy);
elementCopy = ChangeUtil.decodeInformation(elementCopy);
final PsiElement result = SourceTreeToPsiMap.treeElementToPsi(elementCopy);
this.invalidate();
return result;
}
示例12: addBefore
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
public PsiElement addBefore(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
CheckUtil.checkWritable(this);
TreeElement elementCopy = ChangeUtil.copyToElement(element);
calcTreeElement().addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.TRUE);
elementCopy = ChangeUtil.decodeInformation(elementCopy);
return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
示例13: addAfter
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
public PsiElement addAfter(@NotNull PsiElement element, @Nullable PsiElement anchor) throws IncorrectOperationException {
CheckUtil.checkWritable(this);
TreeElement elementCopy = ChangeUtil.copyToElement(element);
calcTreeElement().addInternal(elementCopy, elementCopy, SourceTreeToPsiMap.psiElementToTree(anchor), Boolean.FALSE);
elementCopy = ChangeUtil.decodeInformation(elementCopy);
return SourceTreeToPsiMap.treeElementToPsi(elementCopy);
}
示例14: checkCreateSubdirectory
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
@Override
public void checkCreateSubdirectory(@NotNull String name) throws IncorrectOperationException {
// TODO : another check?
//CheckUtil.checkIsIdentifier(name);
VirtualFile existingFile = getVirtualFile().findChild(name);
if (existingFile != null) {
throw new IncorrectOperationException(VfsBundle.message("file.already.exists.error", existingFile.getPresentableUrl()));
}
CheckUtil.checkWritable(this);
}
示例15: doReplace
import com.intellij.psi.impl.CheckUtil; //导入方法依赖的package包/类
public static PsiElement doReplace(PsiElement psiElement, TreeElement treeElement, PsiElement newElement) {
CompositeElement treeParent = treeElement.getTreeParent();
LOG.assertTrue(treeParent != null);
CheckUtil.checkWritable(psiElement);
TreeElement elementCopy = ChangeUtil.copyToElement(newElement);
treeParent.replaceChildInternal(treeElement, elementCopy);
elementCopy = ChangeUtil.decodeInformation(elementCopy);
final PsiElement result = SourceTreeToPsiMap.treeElementToPsi(elementCopy);
treeElement.invalidate();
return result;
}